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() {
32123212
32133213 if (diagnoseForDynamicCallable ())
32143214 return true ;
3215+
3216+ if (diagnoseInLiteralCollectionContext ())
3217+ return true ;
32153218
32163219 auto baseType = resolveType (getBaseType ())->getWithoutSpecifierType ();
32173220
@@ -3399,6 +3402,37 @@ bool MissingMemberFailure::diagnoseForDynamicCallable() const {
33993402 return false ;
34003403}
34013404
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+
34023436bool InvalidMemberRefOnExistential::diagnoseAsError () {
34033437 auto anchor = getRawAnchor ();
34043438
Original file line number Diff line number Diff line change @@ -1059,6 +1059,10 @@ class MissingMemberFailure final : public InvalidMemberRefFailure {
10591059 // / overload to be present, but a class marked as `@dynamicCallable`
10601060 // / defines only `dynamicallyCall(withArguments:)` variant.
10611061 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 ;
10621066
10631067 static DeclName findCorrectEnumCaseName (Type Ty,
10641068 TypoCorrectionResults &corrections,
Original file line number Diff line number Diff line change @@ -664,3 +664,12 @@ func test_34770265(_ dict: [Int: Int]) {
664664 dict. rdar_34770265_val ( )
665665 // expected-error@-1 {{referencing instance method 'rdar_34770265_val()' on 'Dictionary' requires the types 'Int' and 'String' be equivalent}}
666666}
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