diff --git a/spec/compiler/codegen/class_spec.cr b/spec/compiler/codegen/class_spec.cr index e16788d453b4..9b6a935a775a 100644 --- a/spec/compiler/codegen/class_spec.cr +++ b/spec/compiler/codegen/class_spec.cr @@ -659,7 +659,7 @@ describe "Code gen: class" do )).to_string.should eq("Baz") end - it "does not combine types with same name but different file scopes (#15503)" do + it "does not combine metaclass types with same name but different file scopes (#15503)" do run(<<-CRYSTAL, Int32, filename: "foo.cr").should eq(11) module Foo def self.foo @@ -691,6 +691,72 @@ describe "Code gen: class" do CRYSTAL end + it "does not combine virtual types with same name but different file scopes" do + run(<<-CRYSTAL, Int32, filename: "foo.cr").should eq(101) + class Foo + def foo + 1 + end + end + + class Bar1 < Foo + def foo + 10 + end + end + + alias Fred = Foo + {% Fred %} # forces immediate resolution of `Foo` + + private class Foo + def foo + 100 + end + end + + private class Bar2 < Foo + def foo + 1000 + end + end + + Fred.new.as(Fred).foo &+ Foo.new.as(Foo).foo + CRYSTAL + end + + it "does not combine virtual metaclass types with same name but different file scopes" do + run(<<-CRYSTAL, Int32, filename: "foo.cr").should eq(101) + class Foo + def self.foo + 1 + end + end + + class Bar1 < Foo + def self.foo + 10 + end + end + + alias Fred = Foo + {% Fred %} # forces immediate resolution of `Foo` + + private class Foo + def self.foo + 100 + end + end + + private class Bar2 < Foo + def self.foo + 1000 + end + end + + Fred.as(Fred.class).foo &+ Foo.as(Foo.class).foo + CRYSTAL + end + it "builds generic class bug" do codegen(%( abstract class Base diff --git a/src/compiler/crystal/codegen/match.cr b/src/compiler/crystal/codegen/match.cr index 109366654f29..2d321c91b6dd 100644 --- a/src/compiler/crystal/codegen/match.cr +++ b/src/compiler/crystal/codegen/match.cr @@ -38,7 +38,7 @@ class Crystal::CodeGenVisitor end private def match_any_type_id_with_function(type, type_id) - match_fun_name = "~match<#{type}>" + match_fun_name = "~match<#{type.llvm_name}>" func = typed_fun?(@main_mod, match_fun_name) || create_match_fun(match_fun_name, type) func = check_main_fun match_fun_name, func call func, [type_id] of LLVM::Value diff --git a/src/compiler/crystal/types.cr b/src/compiler/crystal/types.cr index dc2be80b0ae2..2dfe0352bd46 100644 --- a/src/compiler/crystal/types.cr +++ b/src/compiler/crystal/types.cr @@ -3466,7 +3466,7 @@ module Crystal end def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil - base_type.to_s(io) + base_type.to_s_with_options(io, codegen: codegen) io << '+' end