From 917d41ca2f6fece1e01807d103fa4c5e9d303f7d Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Mon, 22 Mar 2021 21:24:07 +0800 Subject: [PATCH] Match named args by external names when checking overloads (#10530) --- spec/compiler/semantic/def_overload_spec.cr | 11 +++++++++++ src/compiler/crystal/semantic/cover.cr | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/spec/compiler/semantic/def_overload_spec.cr b/spec/compiler/semantic/def_overload_spec.cr index 1921205f3179..3bc8c8d4d56a 100644 --- a/spec/compiler/semantic/def_overload_spec.cr +++ b/spec/compiler/semantic/def_overload_spec.cr @@ -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) diff --git a/src/compiler/crystal/semantic/cover.cr b/src/compiler/crystal/semantic/cover.cr index 2d38312a8d50..b2865decfca8 100644 --- a/src/compiler/crystal/semantic/cover.cr +++ b/src/compiler/crystal/semantic/cover.cr @@ -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