Skip to content

Commit c43c970

Browse files
authored
Merge pull request #64931 from xedin/rdar-100369066
[Diagnostics] Forgo all restrictions if one side of conversion has in…
2 parents 1b319ad + 9816fff commit c43c970

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
@@ -5157,6 +5157,14 @@ bool ConstraintSystem::repairFailures(
51575157
if (auto *inoutExpr = dyn_cast<InOutExpr>(AE->getSrc())) {
51585158
auto *loc = getConstraintLocator(inoutExpr);
51595159

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

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)