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
61 changes: 60 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 metaclass types with same name but different file scopes (#15503)" do
it "does not combine module 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 @@ -757,6 +757,65 @@ describe "Code gen: class" do
CRYSTAL
end

it "does not combine generic virtual metaclass types with same name but different file scopes" do
run(<<-CRYSTAL, Int32, filename: "foo.cr").should eq(11)
module Foo
def self.foo
1
end
end

alias Bar = Foo

{% Bar %} # forces immediate resolution of `Bar`

private module Foo
def self.foo
10
end
end

abstract class Base
end

class Gen(T) < Base
def self.x
T.foo
end
end

Gen(Foo).as(Base.class).x &+ Gen(Bar).as(Base.class).x
CRYSTAL
end

it "does not combine generic module metaclass types with same name but different file scopes" do
run(<<-CRYSTAL, Int32, filename: "foo.cr").should eq(11)
module Foo
def self.foo
1
end
end

alias Bar = Foo

{% Bar %} # forces immediate resolution of `Bar`

private module Foo
def self.foo
10
end
end

module Gen(T)
def self.x
T.foo
end
end

(Gen(Foo) || Gen(Bar)).x &+ (Gen(Bar) || Gen(Foo)).x
CRYSTAL
end

it "builds generic class bug" do
codegen(%(
abstract class Base
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,8 @@ module Crystal
type_var_type.to_s_with_options(io, skip_union_parens: true, codegen: codegen)
end
else
# `type_var` could only be a non-type such as `NumberLiteral`, no
# need to use `#to_s_with_options` here
io << ", " unless first
first = false
type_var.to_s(io)
Expand Down Expand Up @@ -3014,7 +3016,7 @@ module Crystal
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil
instance_type.to_s(io)
instance_type.to_s_with_options(io, codegen: codegen)
io << ".class"
end

Expand Down Expand Up @@ -3068,7 +3070,7 @@ module Crystal
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil
instance_type.to_s(io)
instance_type.to_s_with_options(io, codegen: codegen)
io << ".class"
end

Expand Down