Skip to content

Commit b088aea

Browse files
committed
[ConstraintSystem] Allow fixing r-value -> l-value mismatch without a fix for placeholders
If left-hand side of a conversion that requires l-value is a placeholder type, let's fix that by propagating placeholder to the order side (to allow it to infer a placeholder if needed) without recording a fix since placeholder can be converted to `inout` and/or l-value and already indicates existence of a problem at some other spot in the expression. Resolves: rdar://76250381
1 parent 9345e88 commit b088aea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,12 @@ bool ConstraintSystem::repairFailures(
36673667
TMF_ApplyingFix, locator);
36683668

36693669
if (result.isSuccess()) {
3670+
// If left side is a hole, let's not record a fix since hole can
3671+
// assume any type and already represents a problem elsewhere in
3672+
// the expression.
3673+
if (lhs->isPlaceholder())
3674+
return true;
3675+
36703676
conversionsOrFixes.push_back(
36713677
TreatRValueAsLValue::create(*this, getConstraintLocator(locator)));
36723678
return true;

test/Constraints/closures.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,3 +1084,16 @@ var emptyBodyMismatch: () -> Int {
10841084
return
10851085
}
10861086
}
1087+
1088+
// rdar://76250381 - crash when passing an argument to a closure that takes no arguments
1089+
struct R_76250381<Result, Failure: Error> {
1090+
func test(operation: @escaping () -> Result) -> Bool {
1091+
return try self.crash { group in // expected-error {{contextual closure type '() -> Result' expects 0 arguments, but 1 was used in closure body}}
1092+
operation(&group) // expected-error {{argument passed to call that takes no arguments}}
1093+
}
1094+
}
1095+
1096+
func crash(_: @escaping () -> Result) -> Bool {
1097+
return false
1098+
}
1099+
}

0 commit comments

Comments
 (0)