File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-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 (diagnoseInLiteralCollectionContext ())
3217
+ return true ;
3215
3218
3216
3219
auto baseType = resolveType (getBaseType ())->getWithoutSpecifierType ();
3217
3220
@@ -3399,6 +3402,37 @@ bool MissingMemberFailure::diagnoseForDynamicCallable() const {
3399
3402
return false ;
3400
3403
}
3401
3404
3405
+ bool MissingMemberFailure::diagnoseInLiteralCollectionContext () const {
3406
+ auto &cs = getConstraintSystem ();
3407
+ auto *expr = castToExpr (getAnchor ());
3408
+ auto *parentExpr = cs.getParentExpr (expr);
3409
+ auto &solution = getSolution ();
3410
+
3411
+ if (!(parentExpr && isa<UnresolvedMemberExpr>(expr)))
3412
+ return false ;
3413
+
3414
+ auto parentType = getType (parentExpr);
3415
+
3416
+ if (!cs.isCollectionType (parentType) && !parentType->is <TupleType>())
3417
+ return false ;
3418
+
3419
+ if (isa<TupleExpr>(parentExpr)) {
3420
+ parentExpr = cs.getParentExpr (parentExpr);
3421
+ if (!parentExpr)
3422
+ return false ;
3423
+ }
3424
+
3425
+ if (auto *defaultableVar =
3426
+ cs.getType (parentExpr)->getAs <TypeVariableType>()) {
3427
+ if (solution.DefaultedConstraints .count (
3428
+ defaultableVar->getImpl ().getLocator ()) != 0 ) {
3429
+ emitDiagnostic (diag::unresolved_member_no_inference, getName ());
3430
+ return true ;
3431
+ }
3432
+ }
3433
+ return false ;
3434
+ }
3435
+
3402
3436
bool InvalidMemberRefOnExistential::diagnoseAsError () {
3403
3437
auto anchor = getRawAnchor ();
3404
3438
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 collection literal with unresolved member expression
1064
+ // / that defaults the element type. e.g. _ = [.e]
1065
+ bool diagnoseInLiteralCollectionContext () const ;
1062
1066
1063
1067
static DeclName findCorrectEnumCaseName (Type Ty,
1064
1068
TypoCorrectionResults &corrections,
Original file line number Diff line number Diff line change @@ -664,3 +664,12 @@ func test_34770265(_ dict: [Int: Int]) {
664
664
dict. rdar_34770265_val ( )
665
665
// expected-error@-1 {{referencing instance method 'rdar_34770265_val()' on 'Dictionary' requires the types 'Int' and 'String' be equivalent}}
666
666
}
667
+
668
+ // SR-12672
669
+ _ = [ . e] // expected-error {{reference to member 'e' cannot be resolved without a contextual type}}
670
+ let _ : [ Any ] = [ . e] // expected-error {{type 'Any' has no member 'e'}}
671
+ _ = [ 1 : . e] // expected-error {{reference to member 'e' cannot be resolved without a contextual type}}
672
+ _ = [ . e: 1 ] // expected-error {{reference to member 'e' cannot be resolved without a contextual type}}
673
+ let _ : [ Int : Any ] = [ 1 : . e] // expected-error {{type 'Any' has no member 'e'}}
674
+ let _ : ( Int , Any ) = ( 1 , . e) // expected-error {{type 'Any' has no member 'e'}}
675
+ _ = ( 1 , . e) // expected-error {{cannot infer contextual base in reference to member 'e'}}
You can’t perform that action at this time.
0 commit comments