File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -3212,6 +3212,9 @@ bool MissingMemberFailure::diagnoseAsError() {
3212
3212
3213
3213
if (diagnoseForDynamicCallable ())
3214
3214
return true ;
3215
+
3216
+ if (diagnoseForDefaultAnyArrayLiteral ())
3217
+ return true ;
3215
3218
3216
3219
auto baseType = resolveType (getBaseType ())->getWithoutSpecifierType ();
3217
3220
@@ -3399,6 +3402,29 @@ bool MissingMemberFailure::diagnoseForDynamicCallable() const {
3399
3402
return false ;
3400
3403
}
3401
3404
3405
+ bool MissingMemberFailure::diagnoseForDefaultAnyArrayLiteral () const {
3406
+ auto &cs = getConstraintSystem ();
3407
+ auto *expr = getAsExpr (getAnchor ());
3408
+ auto *parentExpr = cs.getParentExpr (expr);
3409
+ auto contextualType = getContextualType (parentExpr);
3410
+ auto baseType = resolveType (getBaseType ())->getWithoutSpecifierType ();
3411
+
3412
+ if (contextualType)
3413
+ return false ;
3414
+
3415
+ if (isa<UnresolvedMemberExpr>(expr) && isa<ArrayExpr>(parentExpr)) {
3416
+ if (auto *metatype = baseType->getAs <MetatypeType>()) {
3417
+ baseType = metatype->getInstanceType ();
3418
+ }
3419
+
3420
+ if (baseType->isAny ()) {
3421
+ emitDiagnostic (diag::unresolved_member_no_inference, getName ());
3422
+ return true ;
3423
+ }
3424
+ }
3425
+ return false ;
3426
+ }
3427
+
3402
3428
bool InvalidMemberRefOnExistential::diagnoseAsError () {
3403
3429
auto anchor = getRawAnchor ();
3404
3430
Original file line number Diff line number Diff line change @@ -1059,6 +1059,10 @@ class MissingMemberFailure final : public InvalidMemberRefFailure {
1059
1059
// / overload to be present, but a class marked as `@dynamicCallable`
1060
1060
// / defines only `dynamicallyCall(withArguments:)` variant.
1061
1061
bool diagnoseForDynamicCallable () const ;
1062
+
1063
+ // / Tailored diagnostics for array literal with unresolved member expression
1064
+ // / that defaults the element to element type. e.g. _ = [.e]
1065
+ bool diagnoseForDefaultAnyArrayLiteral () const ;
1062
1066
1063
1067
static DeclName findCorrectEnumCaseName (Type Ty,
1064
1068
TypoCorrectionResults &corrections,
You can’t perform that action at this time.
0 commit comments