Skip to content

Commit

Permalink
Showing 2 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions spec/compiler/semantic/generic_class_spec.cr
Original file line number Diff line number Diff line change
@@ -930,4 +930,24 @@ describe "Semantic: generic class" do
Connection(Client).new.packets
)) { generic_class "Array", generic_class("OutgoingPacket", types["Client"]).virtual_type! }
end

it "nests generics with the same type var (#3297)" do
assert_type(%(
class Foo(A)
@a : A
def initialize(@a : A)
end
def a
@a
end
class Bar(A) < Foo(A)
end
end
Foo::Bar.new(:a).a
), inject_primitives: false) { symbol }
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
@@ -67,9 +67,9 @@ class Crystal::Type
# for example Hash(K, V), we want to find K and V as type parameters
# of that type.
if root.is_a?(GenericType)
free_vars = {} of String => TypeVar
free_vars ||= {} of String => TypeVar
root.type_vars.each do |type_var|
free_vars[type_var] = TypeParameter.new(program, root, type_var)
free_vars[type_var] ||= TypeParameter.new(program, root, type_var)
end
@free_vars = free_vars
end

0 comments on commit 83678c4

Please sign in to comment.