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 restrictions in abstract def are not checked when the type doesn't resolve #15359

Open
straight-shoota opened this issue Jan 20, 2025 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@straight-shoota
Copy link
Member

When an abstract def has a type restriction for a type, that does not exist, the compiler doesn't enforce implementation of that def.

The compiler generally ensures that implementing types implement abstract defs. But apparently, it won't do that if a type restriction on the abstract def doesn't resolve.
In the following code, Boo#foo is supposed to implement the abstract def Foo#foo but the parameter's type restriction is different. The compiler doesn't complain about this mismatch. It would complain if we remove Boo#foo entirely, though.

abstract class Foo
  abstract def foo(bar : Bar)
end

class Boo < Foo
  def foo(bar : Baz::Bar)
  end
end

class Baz::Bar
end

Boo.new.foo(Baz::Bar.new)

Introducing a type that the Bar restriction resolves to (e.g. class Foo::Bar; end) makes the compiler realize the abstract def is not implemented correctly: abstract def Foo#foo(bar : Bar) must be implemented by Boo.

Related: #1647

This is a generalization of #15357

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

No branches or pull requests

1 participant