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

Allow union types to be unbound #11166

Merged
merged 1 commit into from
Sep 7, 2021

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Sep 4, 2021

Fixes #9173. In

class Object
  def foo
    self
  end
end

abstract class Parent
end

class Child(T) < Parent
  @buffer = uninitialized T

  def bar
    @buffer.foo # Error: undefined method 'foo' for U (compile-time type is (Char | U))
  end
end

class Foo(U)
  @x = Child(U | Char).new
end

Child(Int32).new.as(Parent).bar

When Parent#bar is called the compiler runs type inference on the implementations in all concrete subtypes of it. This incorrectly included Child(U | Char) because it and U | Char were not considered unbound types. This PR fixes that. (In the original issue this is triggered through Array(T | U)#inspect of an instance variable inside Iterator::InGroupsOf(I, T, N, U).)

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:generics labels Sep 4, 2021
@straight-shoota straight-shoota added this to the 1.2.0 milestone Sep 6, 2021
@straight-shoota straight-shoota merged commit e4890a1 into crystal-lang:master Sep 7, 2021
@HertzDevil HertzDevil deleted the bug/unbound-unions branch September 8, 2021 08:09
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:generics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error including module in some generic classes
3 participants