Skip to content

Commit

Permalink
fix <rdar://problem/20749592> Conditional Optional binding hides comp…
Browse files Browse the repository at this point in the history
…iler error

Swift SVN r28220
  • Loading branch information
lattner committed May 6, 2015
1 parent ab09922 commit ea52d4f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckStmt.cpp
Expand Up @@ -901,6 +901,14 @@ static void diagnoseIgnoredExpr(TypeChecker &TC, Expr *E) {
return;
}

// If we have an OptionalEvaluationExpr at the top level, then someone is
// "optional chaining" and ignoring the result. Produce a diagnostic if it
// doesn't make sense to ignore it.
if (auto *OEE =
dyn_cast<OptionalEvaluationExpr>(E->getSemanticsProvidingExpr()))
if (auto *IIO = dyn_cast<InjectIntoOptionalExpr>(OEE->getSubExpr()))
return diagnoseIgnoredExpr(TC, IIO->getSubExpr());

// FIXME: Complain about literals

// Check if we have a call to a function marked warn_unused_result.
Expand Down
19 changes: 17 additions & 2 deletions test/expr/expressions.swift
Expand Up @@ -506,6 +506,8 @@ ruleVar = Rule("a") // expected-error {{cannot invoke initializer for type 'Rule
class C {
var x: C?
init(other: C?) { x = other }
func method() {}
}
var c = C(3) // expected-error {{cannot invoke initializer for type 'C' with an argument list of type '(Int)'}} expected-note{{expected an argument list of type '(other: C?)'}}
Expand Down Expand Up @@ -587,8 +589,21 @@ func test() {
(&x).method() // expected-error {{cannot invoke 'method' with no arguments}}
}
// Unused l-value
_ // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
// Unused results.
func unusedExpressionResults() {
// Unused l-value
_ // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
// <rdar://problem/20749592> Conditional Optional binding hides compiler error
let optionalc:C? = nil
optionalc?.method() // ok
optionalc?.method // expected-error {{expression resolves to an unused function}}
}
//===----------------------------------------------------------------------===//
// Collection Literals
Expand Down

0 comments on commit ea52d4f

Please sign in to comment.