Skip to content

Commit

Permalink
Compiler: missing replace of type parameters for virtual types. Fixes #…
Browse files Browse the repository at this point in the history
Ary Borenszweig committed Sep 3, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e8ae1f9 commit f76ac03
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/compiler/semantic/generic_class_spec.cr
Original file line number Diff line number Diff line change
@@ -905,4 +905,29 @@ describe "Semantic: generic class" do
),
"expected type, not NumberLiteral"
end

it "replaces type parameters for virtual types (#3235)" do
assert_type(%(
abstract class Packet(T)
end
abstract class OutgoingPacket(T) < Packet(T)
end
class Client
end
class Connection(T)
def initialize
@packets = Array(OutgoingPacket(T)).new
end
def packets
@packets
end
end
Connection(Client).new.packets
)) { generic_class "Array", generic_class("OutgoingPacket", types["Client"]).virtual_type! }
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -2783,6 +2783,10 @@ module Crystal
nil
end

def replace_type_parameters(instance)
base_type.replace_type_parameters(instance).virtual_type
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen = false)
base_type.to_s(io)
io << "+"

0 comments on commit f76ac03

Please sign in to comment.