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

Infinite loop in expanding abstract class with self type #209

Open
Meowcolm024 opened this issue Feb 7, 2024 · 4 comments
Open

Infinite loop in expanding abstract class with self type #209

Meowcolm024 opened this issue Feb 7, 2024 · 4 comments

Comments

@Meowcolm024
Copy link
Collaborator

Meowcolm024 commented Feb 7, 2024

The following code causes an infinite loop in type checking

abstract class Foo[T]: Bar { fun x: T }
abstract class Bar(val x: Int) extends Foo[Int] { fun f(y) = this.x + y }

fun test(f: Foo['a]) = if f is Foo then f.x
  • for an abstract Bar, we have Bar => (#Bar<Object,Foo> & Bar)
  • for a non abstract Bar, we have Bar => #Bar<Object,Foo>
@LPTK
Copy link
Contributor

LPTK commented Feb 7, 2024

Minimized:

abstract class Foo[T]: Foo[Int]
(f: Foo['a]) => f : Str

Minimized further (but the trace looks different):

abstract class Foo: Foo
(f: Foo) => f : Str

@LPTK
Copy link
Contributor

LPTK commented Feb 7, 2024

Another one:

type Foo = Foo & Int
(f: Foo) => f : Str

We have to be more careful when we expand types during normalization...

@LPTK
Copy link
Contributor

LPTK commented Feb 7, 2024

Note that this only happens on the "new parser/typer frontend" (#187). In the legacy frontend, we were careful to check for cycles in definitions and yielded "Error in class definitions: illegal cycle involving type Foo" for the latter example. We have to adapt these sorts of checks to the new frontend.

@LPTK
Copy link
Contributor

LPTK commented Feb 16, 2024

Of course, we can also get unsoundness from such ill-formed types:

type A = A
//│ type A = A

(1 : A)()
//│ nothing
//│ res
//│ Runtime error:
//│   TypeError: 1 is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants