Skip to content

Commit 9db7144

Browse files
committed
[CSDiagnostics] Handle try? contextual mismatch directly
It detends on a situation whether try? would get a type inferred so the mismatch is against a contextual type, or contextual type would be used as a type of `try?` and fail comparsion with inner expression type. In either case the mismatch is contextual.
1 parent d1a11cd commit 9db7144

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,12 @@ bool ContextualFailure::diagnoseAsError() {
18781878
if (diagnoseCoercionToUnrelatedType())
18791879
return true;
18801880

1881+
if (isa<OptionalTryExpr>(anchor)) {
1882+
emitDiagnostic(anchor->getLoc(), diag::cannot_convert_initializer_value,
1883+
getFromType(), getToType());
1884+
return true;
1885+
}
1886+
18811887
return false;
18821888
}
18831889

0 commit comments

Comments
 (0)