@@ -3477,6 +3477,33 @@ bool FailureDiagnosis::diagnoseContextualConversionError() {
3477
3477
return true ;
3478
3478
}
3479
3479
3480
+ // When converting from T to [T] or UnsafePointer<T>, we can offer fixit to wrap
3481
+ // the expr with brackets.
3482
+ if (auto *contextDecl = contextualType->getAnyNominal ()) {
3483
+ if (contextDecl == CS->TC .Context .getArrayDecl ()) {
3484
+ SmallVector<Type, 4 > scratch;
3485
+ for (Type arg : contextualType->getAllGenericArgs (scratch)) {
3486
+ if (arg->isEqual (exprType)) {
3487
+ diagnose (expr->getLoc (), diagID, exprType, contextualType).
3488
+ fixItInsert (expr->getStartLoc (), " [" ).fixItInsert (
3489
+ Lexer::getLocForEndOfToken (CS->TC .Context .SourceMgr ,
3490
+ expr->getEndLoc ()), " ]" );
3491
+ return true ;
3492
+ }
3493
+ }
3494
+ } else if (contextDecl == CS->TC .Context .getUnsafePointerDecl () ||
3495
+ contextDecl == CS->TC .Context .getUnsafeMutablePointerDecl ()) {
3496
+ SmallVector<Type, 4 > scratch;
3497
+ for (Type arg : contextualType->getAllGenericArgs (scratch)) {
3498
+ if (arg->isEqual (exprType)) {
3499
+ diagnose (expr->getLoc (), diagID, exprType, contextualType).
3500
+ fixItInsert (expr->getStartLoc (), " &" );
3501
+ return true ;
3502
+ }
3503
+ }
3504
+ }
3505
+ }
3506
+
3480
3507
// When complaining about conversion to a protocol type, complain about
3481
3508
// conformance instead of "conversion".
3482
3509
if (contextualType->is <ProtocolType>() ||
0 commit comments