mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] Detect and fix extraneous use of &
Diagnose extraneous use of address of (`&`) which could only be
associated with arguments to `inout` parameters e.g.
```swift
struct S {}
var a: S = ...
var b: S = ...
a = &b
```
This commit is contained in:
@@ -2035,7 +2035,7 @@ bool ConstraintSystem::repairFailures(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isa<AssignExpr>(anchor)) {
|
||||
if (auto *AE = dyn_cast<AssignExpr>(anchor)) {
|
||||
if (auto *fnType = lhs->getAs<FunctionType>()) {
|
||||
// If left-hand side is a function type but right-hand
|
||||
// side isn't, let's check it would be possible to fix
|
||||
@@ -2051,6 +2051,12 @@ bool ConstraintSystem::repairFailures(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isa<InOutExpr>(AE->getSrc())) {
|
||||
conversionsOrFixes.push_back(
|
||||
RemoveAddressOf::create(*this, getConstraintLocator(locator)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -6508,6 +6514,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
|
||||
}
|
||||
|
||||
case FixKind::InsertCall:
|
||||
case FixKind::RemoveAddressOf:
|
||||
case FixKind::SkipSameTypeRequirement:
|
||||
case FixKind::SkipSuperclassRequirement:
|
||||
case FixKind::ContextualMismatch:
|
||||
|
||||
Reference in New Issue
Block a user