Skip to content

Commit 1ec7dc9

Browse files
authored
Merge pull request #4422 from slavapestov/fix-try-expr-diagnostic-3.0
Sema: Look through TryExpr in FailureDiagnosis (3.0)
2 parents 81bc25e + 1e4add9 commit 1ec7dc9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,7 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
19821982

19831983
bool visitExpr(Expr *E);
19841984
bool visitIdentityExpr(IdentityExpr *E);
1985+
bool visitTryExpr(TryExpr *E);
19851986
bool visitTupleExpr(TupleExpr *E);
19861987

19871988
bool visitUnresolvedMemberExpr(UnresolvedMemberExpr *E);
@@ -6257,6 +6258,12 @@ bool FailureDiagnosis::visitIdentityExpr(IdentityExpr *E) {
62576258
return false;
62586259
}
62596260

6261+
/// A TryExpr doesn't change it's argument, nor does it change the contextual
6262+
/// type.
6263+
bool FailureDiagnosis::visitTryExpr(TryExpr *E) {
6264+
return visit(E->getSubExpr());
6265+
}
6266+
62606267
bool FailureDiagnosis::visitExpr(Expr *E) {
62616268
// Check each of our immediate children to see if any of them are
62626269
// independently invalid.
@@ -6311,7 +6318,7 @@ void ConstraintSystem::diagnoseFailureForExpr(Expr *expr) {
63116318
// inconsistent state.
63126319
simplify(/*ContinueAfterFailures*/true);
63136320

6314-
// Look through RebindSelfInConstructorExpr to avoid weird sema issues.
6321+
// Look through RebindSelfInConstructorExpr to avoid weird Sema issues.
63156322
if (auto *RB = dyn_cast<RebindSelfInConstructorExpr>(expr))
63166323
expr = RB->getSubExpr();
63176324

test/Constraints/diagnostics.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,3 +769,14 @@ struct SR1752 {
769769
let sr1752: SR1752? = nil
770770

771771
true ? nil : sr1752?.foo() // don't generate a warning about unused result since foo returns Void
772+
773+
// <rdar://problem/27891805> QoI: FailureDiagnosis doesn't look through 'try'
774+
struct rdar27891805 {
775+
init(contentsOf: String, encoding: String) throws {}
776+
init(contentsOf: String, usedEncoding: inout String) throws {}
777+
init<T>(_ t: T) {}
778+
}
779+
780+
try rdar27891805(contentsOfURL: nil, usedEncoding: nil)
781+
// expected-error@-1 {{argument labels '(contentsOfURL:, usedEncoding:)' do not match any available overloads}}
782+
// expected-note@-2 {{overloads for 'rdar27891805' exist with these partially matching parameter lists: (contentsOf: String, encoding: String), (contentsOf: String, usedEncoding: inout String)}}

0 commit comments

Comments
 (0)