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

Compiler: access instantiations of NamedTuple and other generics uniformly #10401

Merged
merged 1 commit into from Feb 18, 2021

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Feb 16, 2021

Fixes #10380.

#10380 (comment) now works. The following will now correctly fail to compile (with the default prelude):

module Foo
end

struct NamedTuple
  include Foo
end

class Bar
  include Foo
end

def foo(x : Bar)
end

x = uninitialized Foo
foo(x)
Error: no overload matches 'foo' with type Foo

Overloads are:
 - foo(x : Bar)
Couldn't find overloads for these types:
 - foo(x : NamedTuple())
 - foo(x : NamedTuple(file: String))
 - foo(x : NamedTuple(time: Time, location: Time::Location))

This replaces Crystal::GenericType#generic_types with #instantiated_types, so that Crystal::NamedTupleType can redefine it. Note that the keys of Crystal::GenericType#@generic_types and Crystal::NamedTupleType#@instantiations are never accessed outside those compiler types' instantiation methods repsectively (they are only used for caching instantiations with the same type arguments).

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! ❤️

@bcardiff bcardiff added this to the 1.0.0 milestone Feb 18, 2021
@bcardiff bcardiff merged commit 0f974f0 into crystal-lang:master Feb 18, 2021
@HertzDevil HertzDevil deleted the bug/named-tuple-instances branch February 19, 2021 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants