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

Unsubstituted generic type argument can leak in generic subclass #10834

Open
HertzDevil opened this issue Jun 18, 2021 · 0 comments · May be fixed by #10839
Open

Unsubstituted generic type argument can leak in generic subclass #10834

HertzDevil opened this issue Jun 18, 2021 · 0 comments · May be fixed by #10839
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@HertzDevil
Copy link
Contributor

This was discovered while writing #3649 (comment). Consider:

class Foo(T1)
  def foo
    {T1}
  end
end

class Bar(T2) < Foo(T2)
  def bar
    {T1, T2}
  end
end

x = Bar(Int32).new
x.foo # => {Int32}
x.bar # => {T2, Int32}

This T2 on the last line corresponds to the formal argument in Bar(T2)'s superclass, i.e. it is a Crystal::TypeParameter, formed by substituting T1. The same also happens if that argument is a nested generic like Array(T2) or a splat like *T2 (in that case the type is a Crystal::TypeSplat instead).

This means those type parameters must be substituted repeatedly until no formal parameters appear in the type.

@HertzDevil HertzDevil added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jun 18, 2021
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

Successfully merging a pull request may close this issue.

2 participants