diff --git a/spec/compiler/semantic/splat_spec.cr b/spec/compiler/semantic/splat_spec.cr index f4e9b46539c9..823becb17b45 100644 --- a/spec/compiler/semantic/splat_spec.cr +++ b/spec/compiler/semantic/splat_spec.cr @@ -405,6 +405,16 @@ describe "Semantic: splat" do )) { tuple_of([] of Type).metaclass } end + it "uses splat restriction after non-splat arguments (#5037)" do + assert_type(%( + def foo(x, *y : *T) forall T + T + end + + foo 1, 'a', "" + )) { tuple_of([char, string]).metaclass } + end + it "uses splat restriction with concrete type" do assert_error %( struct Tuple(T) diff --git a/src/compiler/crystal/semantic/method_lookup.cr b/src/compiler/crystal/semantic/method_lookup.cr index be17ef161ac3..d35c71c076ee 100644 --- a/src/compiler/crystal/semantic/method_lookup.cr +++ b/src/compiler/crystal/semantic/method_lookup.cr @@ -262,6 +262,9 @@ module Crystal unless match_arg_type return nil end + + matched_arg_types ||= [] of Type + matched_arg_types.concat(splat_arg_types) end found_unmatched_named_arg = false