Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 67 additions & 1 deletion spec/compiler/codegen/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/match.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading