Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4bec3100b555
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5362e25d22f8
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 19, 2017

  1. Fix macro method lookup

    asterite committed Aug 19, 2017
    Copy the full SHA
    49f7bac View commit details
  2. Copy the full SHA
    5362e25 View commit details
Showing with 51 additions and 0 deletions.
  1. +47 −0 spec/compiler/semantic/macro_spec.cr
  2. +4 −0 src/compiler/crystal/types.cr
47 changes: 47 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
@@ -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