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 @@ -3236,6 +3236,9 @@ bool MissingMemberFailure::diagnoseAsError() {
3236
3236
3237
3237
if (diagnoseForDynamicCallable ())
3238
3238
return true ;
3239
+
3240
+ if (diagnoseInLiteralCollectionContext ())
3241
+ return true ;
3239
3242
3240
3243
auto baseType = resolveType (getBaseType ())->getWithoutSpecifierType ();
3241
3244
@@ -3424,6 +3427,37 @@ bool MissingMemberFailure::diagnoseForDynamicCallable() const {
3424
3427
return false ;
3425
3428
}
3426
3429
3430
+ bool MissingMemberFailure::diagnoseInLiteralCollectionContext () const {
3431
+ auto &cs = getConstraintSystem ();
3432
+ auto *expr = castToExpr<Expr>(getAnchor ());
3433
+ auto *parentExpr = findParentExpr (expr);
3434
+ auto &solution = getSolution ();
3435
+
3436
+ if (!(parentExpr && isa<UnresolvedMemberExpr>(expr)))
3437
+ return false ;
3438
+
3439
+ auto parentType = getType (parentExpr);
3440
+
3441
+ if (!cs.isCollectionType (parentType) && !parentType->is <TupleType>())
3442
+ return false ;
3443
+
3444
+ if (isa<TupleExpr>(parentExpr)) {
3445
+ parentExpr = findParentExpr (parentExpr);
3446
+ if (!parentExpr)
3447
+ return false ;
3448
+ }
3449
+
3450
+ if (auto *defaultableVar =
3451
+ cs.getType (parentExpr)->getAs <TypeVariableType>()) {
3452
+ if (solution.DefaultedConstraints .count (
3453
+ defaultableVar->getImpl ().getLocator ()) != 0 ) {
3454
+ emitDiagnostic (diag::unresolved_member_no_inference, getName ());
3455
+ return true ;
3456
+ }
3457
+ }
3458
+ return false ;
3459
+ }
3460
+
3427
3461
bool InvalidMemberRefOnExistential::diagnoseAsError () {
3428
3462
auto anchor = getRawAnchor ();
3429
3463
Original file line number Diff line number Diff line change @@ -1076,6 +1076,10 @@ class MissingMemberFailure final : public InvalidMemberRefFailure {
1076
1076
// / overload to be present, but a class marked as `@dynamicCallable`
1077
1077
// / defines only `dynamicallyCall(withArguments:)` variant.
1078
1078
bool diagnoseForDynamicCallable () const ;
1079
+
1080
+ // / Tailored diagnostics for collection literal with unresolved member expression
1081
+ // / that defaults the element type. e.g. _ = [.e]
1082
+ bool diagnoseInLiteralCollectionContext () const ;
1079
1083
1080
1084
static DeclName findCorrectEnumCaseName (Type Ty,
1081
1085
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