The following code throws ClassCastException at runtime, should instead be a compiler error
class HelloFantom{
Void main(){
HelloFantom h := false?HelloFantom():"test"
}
}
brianTue 14 Jun 2011
Although not ideal, that is technically the correct behavior from an expression point of view.
The expression false?HelloFantom():"test" has an inferred typed of Obj since that is the common base type between HelloFantom and Str. Then the entire expression is coerced from Obj to HelloFantom using Fantom's normal rules.
kaushik Tue 14 Jun 2011
The following code throws ClassCastException at runtime, should instead be a compiler error
class HelloFantom{ Void main(){ HelloFantom h := false?HelloFantom():"test" } }brian Tue 14 Jun 2011
Although not ideal, that is technically the correct behavior from an expression point of view.
The expression
false?HelloFantom():"test"has an inferred typed ofObjsince that is the common base type betweenHelloFantomandStr. Then the entire expression is coerced fromObjtoHelloFantomusing Fantom's normal rules.