Skip to content

Commit 9e54006

Browse files
committed
[ConstraintSystem] Don't record a mismatch for synthesized arguments
Without context synthesized argument would be inferred as a hole, so let's not record any additional fixes for it if there is no way to infer it properly from a parameter (which could also be a hole if it is a generic parameter type). Resolves: rdar://78781552
1 parent 554e1e4 commit 9e54006

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,10 @@ bool ConstraintSystem::repairFailures(
44604460
// a conversion to another function type, see `matchFunctionTypes`.
44614461
if (parentLoc->isForContextualType() ||
44624462
parentLoc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
4463+
// If either type has a placeholder, consider this fixed.
4464+
if (lhs->hasPlaceholder() || rhs->hasPlaceholder())
4465+
return true;
4466+
44634467
// If there is a fix associated with contextual conversion or
44644468
// a function type itself, let's ignore argument failure but
44654469
// increase a score.

test/Constraints/generics.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,3 +886,22 @@ func rdar78623338() {
886886
// expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
887887
]
888888
}
889+
890+
// rdar://78781552 - crash in `getFunctionArgApplyInfo`
891+
func rdar78781552() {
892+
struct Test<Data, Content> where Data : RandomAccessCollection {
893+
// expected-note@-1 {{where 'Data' = '(((Int) throws -> Bool) throws -> [Int])?'}}
894+
// expected-note@-2 {{'init(data:filter:)' declared here}}
895+
// expected-note@-3 {{'Content' declared as parameter to type 'Test'}}
896+
var data: [Data]
897+
var filter: (Data.Element) -> Content
898+
}
899+
900+
func test(data: [Int]?) {
901+
Test(data?.filter)
902+
// expected-error@-1 {{generic struct 'Test' requires that '(((Int) throws -> Bool) throws -> [Int])?' conform to 'RandomAccessCollection'}}
903+
// expected-error@-2 {{generic parameter 'Content' could not be inferred}} expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}
904+
// expected-error@-3 {{cannot convert value of type '(((Int) throws -> Bool) throws -> [Int])?' to expected argument type '[(((Int) throws -> Bool) throws -> [Int])?]'}}
905+
// expected-error@-4 {{missing argument for parameter 'filter' in call}}
906+
}
907+
}

0 commit comments

Comments
 (0)