File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -3032,6 +3032,10 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
3032
3032
// If we're diagnostic an issue with 'nil', produce a specific diagnostic,
3033
3033
// instead of uttering ExpressibleByNilLiteral.
3034
3034
if (isa<NilLiteralExpr>(expr->getValueProvidingExpr ())) {
3035
+ // If the source type is some kind of optional, the contextual conversion
3036
+ // to 'nil' didn't fail, something else did.
3037
+ if (contextualType->getOptionalObjectType ())
3038
+ return false ;
3035
3039
diagnose (expr->getLoc (), nilDiag, contextualType);
3036
3040
if (nilFollowup)
3037
3041
nilFollowup ();
Original file line number Diff line number Diff line change @@ -26,3 +26,5 @@ var _: Int = nil
26
26
// expected-error@-1 {{nil cannot initialize specified type 'Int'}}
27
27
// expected-note@-2 {{add '?' to form the optional type 'Int?'}} {{11-11=?}}
28
28
29
+ // 'nil' can initialize the specified type, if its generic parameters are bound
30
+ var _: Array ? = nil // expected-error {{generic parameter 'Element' could not be inferred}}
You can’t perform that action at this time.
0 commit comments