Skip to content

Commit

Permalink
Fixed #2982: incorrect type lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Jul 11, 2016
1 parent d4f50a9 commit 6102cb8
Showing 2 changed files with 21 additions and 5 deletions.
19 changes: 19 additions & 0 deletions spec/compiler/type_inference/module_spec.cr
Original file line number Diff line number Diff line change
@@ -947,4 +947,23 @@ describe "Type inference: module" do
{1, 'a'}.u
)) { union_of(int32, char).metaclass }
end

it "doesn't lookup type in ancestor when matches in current type (#2982)" do
assert_error %(
module Foo
module X
class Bar
end
end
end
class X
end
include Foo
X::Bar
),
"undefined constant X::Bar"
end
end
7 changes: 2 additions & 5 deletions src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
@@ -289,11 +289,8 @@ module Crystal
names.each_with_index do |name, i|
next_type = type.types?.try &.[name]?
if !next_type && i != 0
next_type = type.lookup_type_in_parents(names[i..-1])
if next_type
type = next_type
break
end
# Once we find a first type we search in it and don't backtrack
return type.lookup_type_in_parents(names[i..-1])
end
type = next_type
break unless type

0 comments on commit 6102cb8

Please sign in to comment.