mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When adding '!' in fix-it, make sure that it doesn't fall into the
optional evaluation context that produced the optional. <rdar://problem/20377684> Oscillating fixit for optional chain calling method that returns non-optional Swift SVN r28212
This commit is contained in:
@@ -5905,7 +5905,8 @@ Expr *ConstraintSystem::applySolution(Solution &solution, Expr *expr,
|
||||
auto diag = TC.diagnose(affected->getLoc(),
|
||||
diag::missing_unwrap_optional, type);
|
||||
bool parensNeeded = (getInfixData(DC, affected).getPrecedence() <
|
||||
IntrinsicPrecedences::PostfixUnaryExpr);
|
||||
IntrinsicPrecedences::PostfixUnaryExpr) ||
|
||||
isa<OptionalEvaluationExpr>(affected);
|
||||
if (parensNeeded) {
|
||||
diag.fixItInsert(affected->getStartLoc(), "(")
|
||||
.fixItInsertAfter(affected->getEndLoc(), ")!");
|
||||
|
||||
@@ -7,6 +7,7 @@ func f3(Int...) -> Int { }
|
||||
class A { }
|
||||
class B : A {
|
||||
func iAmAB() {}
|
||||
func createB() -> B { return B() }
|
||||
}
|
||||
|
||||
func f4() -> B { }
|
||||
@@ -52,6 +53,11 @@ func forgotOptionalBang(a: A, obj: AnyObject) {
|
||||
|
||||
var a = A(), b = B()
|
||||
b = a as? B // expected-error{{value of optional type 'B?' not unwrapped; did you mean to use '!' or '?'?}}{{7-7=(}}{{14-14=)!}}
|
||||
|
||||
// rdar://problem/20377684 -- take care that the '!' doesn't fall into an
|
||||
// optional evaluation context
|
||||
let bo: B? = b
|
||||
let b2: B = bo?.createB() // expected-error{{value of optional type 'B?' not unwrapped; did you mean to use '!' or '?'?}}{{15-15=(}}{{28-28=)!}}
|
||||
}
|
||||
|
||||
func forgotAnyObjectBang(obj: AnyObject) {
|
||||
|
||||
Reference in New Issue
Block a user