Skip to content

Commit

Permalink
Match named args by external names when checking overloads (#10530)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Mar 22, 2021
1 parent f991977 commit 917d41c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions spec/compiler/semantic/def_overload_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,17 @@ describe "Semantic: def overload" do
"no overload matches"
end

it "errors if no overload matches on union against named arg with external param name (#10516)" do
assert_error %(
def f(a b : Int32)
end
a = 1 || nil
f(a: a)
),
"no overload matches"
end

it "dispatches with named arg" do
assert_type(%(
def f(a : Int32, b : Int32)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/cover.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Crystal
end

signature.named_args.try &.each_with_index do |named_arg, i|
arg = match.def.args.find(&.name.==(named_arg.name))
arg = match.def.args.find(&.external_name.==(named_arg.name))
if arg && (arg.type? || arg.restriction)
indices[args_size + i] = true
end
Expand Down

0 comments on commit 917d41c

Please sign in to comment.