Skip to content

Commit

Permalink
Fix: missing path lookup through alias. Fixes #4645
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and Martin Verzilli committed Sep 16, 2017
1 parent 49f9d28 commit 5c27083
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions spec/compiler/semantic/alias_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,28 @@ describe "Semantic: alias" do
Baz::Bar.baz
)) { int32 }
end

it "finds type through alias (#4645)" do
assert_type(%(
module FooBar
module Foo
A = 10
end
module Bar
include Foo
end
end
class Baz
alias Bar = FooBar::Bar
def test
Bar::A
end
end
Baz.new.test
)) { int32 }
end
end
10 changes: 10 additions & 0 deletions src/compiler/crystal/semantic/path_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ module Crystal
end
end

class AliasType
def lookup_path_item(name : String, lookup_in_namespace, include_private, location)
if aliased_type = aliased_type?
aliased_type.lookup_path_item(name, lookup_in_namespace, include_private, location)
else
super
end
end
end

class TypeDefType
delegate lookup_path, to: typedef
end
Expand Down

0 comments on commit 5c27083

Please sign in to comment.