Skip to content

Commit

Permalink
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/compiler/type_inference/macro_spec.cr
Original file line number Diff line number Diff line change
@@ -884,4 +884,18 @@ describe "Type inference: macro" do
Foo.bar
)) { int32 }
end

it "overrides macro with splat (#2773)" do
assert_type(%(
macro foo(*args)
1
end
macro foo(*args)
'a'
end
foo
)) { char }
end
end
9 changes: 7 additions & 2 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -601,8 +601,13 @@ module Crystal

def lookup_macro(name, args : Array, named_args)
if macros = self.macros.try &.[name]?
match = macros.find &.matches?(args, named_args)
return match if match
# Lookup macros in reverse order so we find ones that
# override others first.
# TODO: macros don't really overload right now, they are
# just a list of macros grouped by name.
macros.reverse_each do |a_macro|
return a_macro if a_macro.matches?(args, named_args)
end
end

instance_type.parents.try &.each do |parent|

0 comments on commit efd1598

Please sign in to comment.