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

Match named arguments by external parameter names when checking overload cover #10530

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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