Skip to content

Commit 9816fff

Browse files
committed
[Diagnostics] Forgo all restrictions if one side of conversion has invalid use of &
None of the restrictions like existential conversion or optional promotion would actually match, so there is no point in trying them just to add more unrelated fixes. Resolves: rdar://100369066
1 parent 756fe15 commit 9816fff

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5156,6 +5156,14 @@ bool ConstraintSystem::repairFailures(
51565156
if (auto *inoutExpr = dyn_cast<InOutExpr>(AE->getSrc())) {
51575157
auto *loc = getConstraintLocator(inoutExpr);
51585158

5159+
// Remove all of the restrictions because none of them
5160+
// are going to succeed.
5161+
conversionsOrFixes.erase(
5162+
llvm::remove_if(
5163+
conversionsOrFixes,
5164+
[](const auto &entry) { return bool(entry.getRestriction()); }),
5165+
conversionsOrFixes.end());
5166+
51595167
if (hasFixFor(loc, FixKind::RemoveAddressOf))
51605168
return true;
51615169

test/Constraints/lvalues.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,11 @@ func test_incorrect_inout_at_assignment_source() {
302302
s.prop = &val // expected-error {{'&' may only be used to pass an argument to inout parameter}}
303303
}
304304
}
305+
306+
// rdar://100369066 - type of expression is ambiguous when `&` is used incorrectly
307+
func test_invalid_inout_with_restrictions(lhs: inout any BinaryInteger, rhs: any BinaryInteger) {
308+
lhs = &rhs // expected-error {{'&' may only be used to pass an argument to inout parameter}}
309+
310+
var other: (any BinaryInteger)? = nil
311+
other = &rhs // expected-error {{'&' may only be used to pass an argument to inout parameter}}
312+
}

0 commit comments

Comments
 (0)