Skip to content

Commit 3a493b2

Browse files
authored
Merge pull request #5286 from xedin/SR-2505-v2
SR-2505: Fix "Call arguments did not match up" assertion
2 parents 3d7f8cc + 578e36a commit 3a493b2

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -614,24 +614,6 @@ static ConstraintSystem::SolutionKind
614614
matchCallArguments(ConstraintSystem &cs, TypeMatchKind kind,
615615
Type argType, Type paramType,
616616
ConstraintLocatorBuilder locator) {
617-
618-
// In the empty existential parameter case, we don't need to decompose the
619-
// arguments.
620-
if (paramType->isEmptyExistentialComposition()) {
621-
if (argType->is<InOutType>())
622-
return ConstraintSystem::SolutionKind::Error;
623-
624-
// If the param type is an empty existential composition, the function can
625-
// only have one argument. Check if exactly one argument was passed to this
626-
// function, otherwise we obviously have a mismatch
627-
if (auto tupleArgType = dyn_cast<TupleType>(argType.getPointer())) {
628-
if (tupleArgType->getNumElements() != 1) {
629-
return ConstraintSystem::SolutionKind::Error;
630-
}
631-
}
632-
return ConstraintSystem::SolutionKind::Solved;
633-
}
634-
635617
// Extract the parameters.
636618
ValueDecl *callee;
637619
unsigned calleeLevel;
@@ -653,6 +635,16 @@ matchCallArguments(ConstraintSystem &cs, TypeMatchKind kind,
653635
parameterBindings))
654636
return ConstraintSystem::SolutionKind::Error;
655637

638+
// In the empty existential parameter case,
639+
// it's sufficient to simply match call arguments.
640+
if (paramType->isEmptyExistentialComposition()) {
641+
// Argument of the existential type can't be inout.
642+
if (argType->is<InOutType>())
643+
return ConstraintSystem::SolutionKind::Error;
644+
645+
return ConstraintSystem::SolutionKind::Solved;
646+
}
647+
656648
// Check the argument types for each of the parameters.
657649
unsigned subflags = ConstraintSystem::TMF_GenerateConstraints;
658650
TypeMatchKind subKind;

test/Constraints/closures.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,35 @@ func r20789423() {
324324
}
325325

326326
let f: (Int, Int) -> Void = { x in } // expected-error {{contextual closure type specifies '(Int, Int)', but 1 was used in closure body, try adding extra parentheses around the single tuple argument}}
327+
328+
// Make sure that behavior related to allowing trailing closures to match functions
329+
// with Any as a final parameter is the same after the changes made by SR-2505, namely:
330+
// that we continue to select function that does _not_ have Any as a final parameter in
331+
// presence of other posibilities.
332+
333+
protocol SR_2505_Initable { init() }
334+
struct SR_2505_II : SR_2505_Initable {}
335+
336+
protocol P_SR_2505 {
337+
associatedtype T: SR_2505_Initable
338+
}
339+
340+
extension P_SR_2505 {
341+
func test(it o: (T) -> Bool) -> Bool {
342+
return o(T.self())
343+
}
344+
}
345+
346+
class C_SR_2505 : P_SR_2505 {
347+
typealias T = SR_2505_II
348+
349+
func test(_ o: Any) -> Bool {
350+
return false
351+
}
352+
353+
func call(_ c: C_SR_2505) -> Bool {
354+
return c.test { o in test(o) }
355+
}
356+
}
357+
358+
let _ = C_SR_2505().call(C_SR_2505())

test/Constraints/diagnostics.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,3 +821,29 @@ func foo1255_1() {
821821
func foo1255_2() -> Int {
822822
return true || false // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
823823
}
824+
825+
// SR-2505: "Call arguments did not match up" assertion
826+
827+
func sr_2505(_ a: Any) {} // expected-note {{}}
828+
sr_2505() // expected-error {{missing argument for parameter #1 in call}}
829+
sr_2505(a: 1) // expected-error {{extraneous argument label 'a:' in call}}
830+
sr_2505(1, 2) // expected-error {{extra argument in call}}
831+
sr_2505(a: 1, 2) // expected-error {{extra argument in call}}
832+
833+
struct C_2505 {
834+
init(_ arg: Any) {
835+
}
836+
}
837+
838+
protocol P_2505 {
839+
}
840+
841+
extension C_2505 {
842+
init<T>(from: [T]) where T: P_2505 {
843+
}
844+
}
845+
846+
class C2_2505: P_2505 {
847+
}
848+
849+
let c_2505 = C_2505(arg: [C2_2505()]) // expected-error {{argument labels '(arg:)' do not match any available overloads}} expected-note {{overloads for 'C_2505' exist}}

0 commit comments

Comments
 (0)