#1942 Err when making of err

Akcelisto Sun 8 Jul 2012

I write custom err and I meet two issue with err.

1) Why this is not compiled?

const class MyErr : Err{}  

Compiler output:

ErrTest.fan(7,9): Must call super class constructor in 'make'

However sys::Err.make is exists.

2) Why this test is failed?

class ErrTest : Test{
  Void testMake(){
    err := MyErr()
  }
}

const class MyErr : Err{
  new make():super.make(){}
}

This compiles but throws err:

sys::NullErr: msg is null
  fan.sys.Err.make$ (Err.java:87)
  fan.sys.Err.make$ (Err.java:84)
  fan.sys.Err.make$ (Err.java:83)
  testPod::MyErr.make$ (ErrTest.fan:8)
  testPod::MyErr.make (ErrTest.fan:8)
  testPod::ErrTest.testMake (ErrTest.fan:3)  
  ...

brian Sun 8 Jul 2012

  1. Means you have to declare a constructor which calls the super class constructor with required arguments - just like Java, different syntax
  2. The msg parameter is typed as Str, not Str? which means null is not allowed (hard to tell from you code what is going on there)

Akcelisto Mon 9 Jul 2012

1) I always think that compiler pastes ctor in my class if I dont.

This code

const class MyErr : Err{}

compiles into

const class MyErr : Err{
  new make():super.make(){}
}

Probably, diff is in optional and required args. This not compiles too:

class A{
  new make(Str? p := null){}
}
class B : A{

} 

Ok. Now I understand 1).

2) May you give me more details? Why hard to tell? This is all code. I post my test a whole. I cant see msg in my test. I cant see null in my test. Where null is not allowed?

SlimerDude Mon 9 Jul 2012

Given that the sys::Err ctor is

new make(Str msg := "", Err? cause := null)

then I too would expect the following to work, but with an empty Str msg:

const class MyErr : Err {
  new make() : super.make() {}
}

But as Akcelisto says, a NullErr is thrown.

It's weird, cos looking at the Err java code:

public static Err make() { return make("", (Err)null); }

it all looks good!

Akcelisto Mon 9 Jul 2012

(1) is compiler feature: optional args became reqiured args in ctor inheritance when compiler pastes default ctor. Compiler cant paste default ctor with optional args.

(However, I think, compiler can be improved in this case.)

But (2) is bug. This code must not throw any exception:

class ErrTest : Test{
  Void testMake(){
    err := MyErr()
  }
}

const class MyErr : Err{
  new make():super.make(){}
}

This test must be successful.

brian Mon 9 Jul 2012

Promoted to ticket #1942 and assigned to brian

Optional parameters still must be declared by subclasses, so that is by design.

I can't test that snippet code at the moment, but it shouldn't be compiling and failing in that way. It is probably related to Err getting implemented by hand in Java. So I will take a look.

brian Sun 15 Jul 2012

Ticket resolved in 1.0.64

It was just a bug in the hand coded constructor for Err.java, Err.cs

changeset

Login or Signup to reply.