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
32 changes: 32 additions & 0 deletions spec/compiler/codegen/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,38 @@ 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
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 Baz
def self.foo
100
end
end

def foo(x)
x.foo
end

foo(Foo || Baz) &+ foo(Bar || Baz)
CRYSTAL
end

it "builds generic class bug" do
codegen(%(
abstract class Base
Expand Down
6 changes: 6 additions & 0 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2948,6 +2948,12 @@ module Crystal
end

def to_s_with_options(io : IO, skip_union_parens : Bool = false, generic_args : Bool = true, codegen : Bool = false) : Nil
if codegen
if (namespace = instance_type.namespace).is_a?(FileModule)
namespace.to_s_with_options(io, generic_args: false, codegen: codegen)
io << "::"
end
end
io << @name
end

Expand Down