You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Foo
{
BarFactory.make() @=> Bar bar;
}
class Bar
{
"i am bar" => string name;
}
class BarChild extends Bar
{
"i extend bar" => name;
}
class BarFactory
{
fun static BarChild make()
{
return new BarChild;
}
}
compiler error:
error: cannot assign '@=>' on types 'BarChild' @=> 'Bar'...
[3] BarFactory.make() @=> Bar bar;
^
error: |- reason: incompatible types for assignment
[3] BarFactory.make() @=> Bar bar;
Cause: class definitions are processed across several phase (scan0, scan1, scan2, type-checking, code-emission). While the new Type defined by the class (e.g., BarChild) is created during scan (scan0), the inheritance (class BarChild extends Bar) is not processed until the type-checking phase, where it is done in the order it appears in the code. In this case, since Foo's BarFactory.make() @=> Bar bar; occurs before class BarChild extends Bar, Bar and BarChild are known but that BarChild extends Bar is not yet known to the type system.
Possible Remedy:
move the class inheritance check earlier, from type-checking potentially into scan1 or scan2 (and leave the class body portion in type-checking)
need to check for circular extensions e.g., A extend B and B extends A
(FYI issue uncovered while addressing #348 cc @nshaheed @heuremh)
The text was updated successfully, but these errors were encountered:
gewang
changed the title
type extension not taken into account depending order of declaration
type inheritance not taken into account depending on order of declaration
Aug 20, 2023
The following code should work, but does not:
compiler error:
Cause: class definitions are processed across several phase (scan0, scan1, scan2, type-checking, code-emission). While the new Type defined by the class (e.g.,
BarChild
) is created during scan (scan0), the inheritance (class BarChild extends Bar
) is not processed until the type-checking phase, where it is done in the order it appears in the code. In this case, sinceFoo
'sBarFactory.make() @=> Bar bar;
occurs beforeclass BarChild extends Bar
,Bar
andBarChild
are known but thatBarChild
extendsBar
is not yet known to the type system.Possible Remedy:
A extend B
andB extends A
(FYI issue uncovered while addressing #348 cc @nshaheed @heuremh)
The text was updated successfully, but these errors were encountered: