Skip to content

[ConstraintSystem] Don't record a mismatch for synthesized arguments #37778

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

Merged
merged 1 commit into from
Jun 4, 2021
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
4 changes: 4 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4460,6 +4460,10 @@ bool ConstraintSystem::repairFailures(
// a conversion to another function type, see `matchFunctionTypes`.
if (parentLoc->isForContextualType() ||
parentLoc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
// If either type has a placeholder, consider this fixed.
if (lhs->hasPlaceholder() || rhs->hasPlaceholder())
return true;

// If there is a fix associated with contextual conversion or
// a function type itself, let's ignore argument failure but
// increase a score.
Expand Down
19 changes: 19 additions & 0 deletions test/Constraints/generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,22 @@ func rdar78623338() {
// expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
]
}

// rdar://78781552 - crash in `getFunctionArgApplyInfo`
func rdar78781552() {
struct Test<Data, Content> where Data : RandomAccessCollection {
// expected-note@-1 {{where 'Data' = '(((Int) throws -> Bool) throws -> [Int])?'}}
// expected-note@-2 {{'init(data:filter:)' declared here}}
// expected-note@-3 {{'Content' declared as parameter to type 'Test'}}
var data: [Data]
var filter: (Data.Element) -> Content
}

func test(data: [Int]?) {
Test(data?.filter)
// expected-error@-1 {{generic struct 'Test' requires that '(((Int) throws -> Bool) throws -> [Int])?' conform to 'RandomAccessCollection'}}
// expected-error@-2 {{generic parameter 'Content' could not be inferred}} expected-note@-2 {{explicitly specify the generic arguments to fix this issue}}
// expected-error@-3 {{cannot convert value of type '(((Int) throws -> Bool) throws -> [Int])?' to expected argument type '[(((Int) throws -> Bool) throws -> [Int])?]'}}
// expected-error@-4 {{missing argument for parameter 'filter' in call}}
}
}