[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:
Pavel Yaskevich
2019-05-06 11:18:47 -07:00
parent 43526d031c
commit 3af163a94c
5 changed files with 61 additions and 1 deletions

View File

@@ -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: