Skip to content

Commit

Permalink
Fixed #3647: incorrect codegen for dispatch with union and module
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 7, 2016
1 parent 988005c commit ed790ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions spec/compiler/codegen/module_spec.cr
Expand Up @@ -596,4 +596,30 @@ describe "Code gen: module" do
bar.as(Moo(Char)).moo
)).to_i.should eq(10)
end

it "codegend dispatch of union with module (#3647)" do
run(%(
module Moo
end
class Foo
include Moo
end
class Bar < Foo
end
def foo(x : Int32)
1
end
def foo(x)
234
end
m = Bar.new.as(Moo)
a = m || 1
foo(a)
)).to_i.should eq(234)
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/codegen/types.cr
Expand Up @@ -80,7 +80,7 @@ module Crystal
class NonGenericModuleType
def append_to_expand_union_types(types)
if including_types = @including_types
including_types.each &.append_to_expand_union_types(types)
including_types.each &.virtual_type.append_to_expand_union_types(types)
else
types << self
end
Expand All @@ -90,7 +90,7 @@ module Crystal
class GenericModuleInstanceType
def append_to_expand_union_types(types)
if including_types = @including_types
including_types.each &.append_to_expand_union_types(types)
including_types.each &.virtual_type.append_to_expand_union_types(types)
else
types << self
end
Expand Down

0 comments on commit ed790ae

Please sign in to comment.