Skip to content

Commit

Permalink
Fix type def reopening type from parent namespace (#11208)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Apr 13, 2024
1 parent 0c67224 commit 0efbf53
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/compiler/semantic/class_spec.cr
Expand Up @@ -383,6 +383,20 @@ describe "Semantic: class" do
") { char }
end

it "type def does not reopen type from parent namespace (#11181)" do
assert_type <<-CR, inject_primitives: false { types["Baz"].types["Foo"].types["Bar"].metaclass }
class Foo::Bar
end
module Baz
class Foo::Bar
end
end
Baz::Foo::Bar
CR
end

it "finds in global scope if includes module" do
assert_type("
class Baz
Expand Down
14 changes: 14 additions & 0 deletions spec/compiler/semantic/module_spec.cr
Expand Up @@ -898,6 +898,20 @@ describe "Semantic: module" do
)) { types["Foo"].types["Bar"].types["Baz"].metaclass }
end

it "type def does not reopen type from parent namespace (#11181)" do
assert_type <<-CR, inject_primitives: false { types["Baz"].types["Foo"].types["Bar"].metaclass }
module Foo::Bar
end
module Baz
module Foo::Bar
end
end
Baz::Foo::Bar
CR
end

it "correctly types type var in included module, with a restriction with a free var (bug)" do
assert_type(%(
module Moo(T)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/top_level_visitor.cr
Expand Up @@ -1275,7 +1275,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor

def lookup_type_def_name_creating_modules(path : Path)
base_type = path.global? ? program : current_type
target_type = base_type.lookup_path(path).as?(Type).try &.remove_alias_if_simple
target_type = base_type.lookup_path(path, lookup_in_namespace: false).as?(Type).try &.remove_alias_if_simple

unless target_type
next_type = base_type
Expand Down

0 comments on commit 0efbf53

Please sign in to comment.