I have a problem similar to http://fantom.org/forum/topic/2579 but after read it and test it, I can't solve my problem. Please help me to find the error.
const abstract class Generation
{
const Int genes
const Int size
const Float rate
name make(|This| f)
{
f(this)
if (genes == null || genes < 1)
throw ArgErr("...")
if (size == null || size < 1)
throw ArgErr("...")
if (rate == null)
rate = 0.0f
}
abstract Obj makeRndGen(Float probability)
... more methods
}
const class BitGeneration : Generation
{
new make(|This| f) : super.make(f)
{
if (rate == null)
rate = 0.5f
}
override Obj makeRndGen(Float probability)
{
probability < rate ? true : false
}
}
fansh> b := BitGeneration { genes=3; size=2 }
sys::Err: java.lang.VerifyError: (class: fan/ga/Generation, method: make$
signature: (Lfan/ga/Generation;Lfan/sys/Func;)V) Expecting to find object/array
on stack
I have tried to initialize all the values in Generation constructor and in BitGeneration constructor but I don't find the solution.
Can you help me? Thanks.
SlimerDudeFri 27 Jan 2017
This looks to be a Fantom bug to me. Here's a simplified example:
class SuperClass {
const Int field
new make(|This|? f) {
f?.call(this)
if (field == null)
field = 9
}
}
class SubClass : SuperClass {
new make(|This|? f) : super(f) { }
}
Which gives:
sys::Err: java.lang.VerifyError: (class: fan/afFantomLang/SuperClass, method: make$ signature: (Lfan/afFantomLang/SuperClass;Lfan/sys/Func;)V) Expecting to find object/array on stack
afExample::Example.main (Example.fan:19)
java.lang.reflect.Method.invoke (Method.java:597)
...
The error is caused by the null check:
if (field == null)
A work around for now is to make the fields nullable:
This didn't really have anything to do with the sub-class. It was a problem with how the compiler allows it-block constructors to do special checks against non-nullable fields during construction. But it wasn't taking value fields into account properly.
fraya Thu 26 Jan 2017
I have a problem similar to http://fantom.org/forum/topic/2579 but after read it and test it, I can't solve my problem. Please help me to find the error.
I have tried to initialize all the values in
Generation
constructor and inBitGeneration
constructor but I don't find the solution.Can you help me? Thanks.
SlimerDude Fri 27 Jan 2017
This looks to be a Fantom bug to me. Here's a simplified example:
Which gives:
The error is caused by the null check:
A work around for now is to make the fields nullable:
brian Wed 4 Oct 2017
Ticket promoted to #2592 and assigned to brian
brian Wed 4 Oct 2017
Ticket resolved in 1.0.70
This didn't really have anything to do with the sub-class. It was a problem with how the compiler allows it-block constructors to do special checks against non-nullable fields during construction. But it wasn't taking value fields into account properly.