Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macro method lookup #4857

Merged
merged 2 commits into from Aug 19, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Expand Up @@ -1122,4 +1122,51 @@ describe "Semantic: macro" do
Moo.bar
), inject_primitives: false) { int32 }
end

it "finds metaclass instance of instance method (#4739)" do
assert_type(%(
class Parent
macro foo
def self.bar
1
end
end
end

class Child < Parent
def foo
end
end

class GrandChild < Child
foo
end

GrandChild.bar
)) { int32 }
end

it "finds metaclass instance of instance method (#4639)" do
assert_type(%(
module Include
macro foo
def foo
1
end
end
end

class Parent
include Include

foo
end

class Foo < Parent
foo
end

Foo.new.foo
)) { int32 }
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/types.cr
Expand Up @@ -410,6 +410,8 @@ module Crystal
# We need to go through the instance type because of module
# inclusion and inheritance.
instance_type.parents.try &.each do |parent|
# Make sure to start the search in the metaclass if we are a metaclass
parent = parent.metaclass if self.metaclass?
parent_macro = parent.lookup_macro(name, args, named_args)
return parent_macro if parent_macro
end
Expand All @@ -436,6 +438,8 @@ module Crystal
# We need to go through the instance type because of module
# inclusion and inheritance.
instance_type.parents.try &.each do |parent|
# Make sure to start the search in the metaclass if we are a metaclass
parent = parent.metaclass if self.metaclass?
parent_macros = parent.lookup_macros(name)
return parent_macros if parent_macros
end
Expand Down