Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type inheritance not taken into account depending on order of declaration #349

Closed
gewang opened this issue Aug 20, 2023 · 2 comments
Closed
Labels

Comments

@gewang
Copy link
Member

gewang commented Aug 20, 2023

The following code should work, but does not:

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:

  1. move the class inheritance check earlier, from type-checking potentially into scan1 or scan2 (and leave the class body portion in type-checking)
  2. need to check for circular extensions e.g., A extend B and B extends A

(FYI issue uncovered while addressing #348 cc @nshaheed @heuremh)

@gewang 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
@gewang gewang added the bug label Aug 20, 2023
@heuermh
Copy link
Contributor

heuermh commented Aug 20, 2023

See also related issue #107

@gewang
Copy link
Member Author

gewang commented Dec 5, 2023

addressed in dbcec84 and b620658; will be part of 1.5.2.0 release

@gewang gewang closed this as completed Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants