@@ -2016,7 +2016,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2016
2016
// comes up and is otherwise non-obvious what is going on.
2017
2017
2018
2018
if (Name.isSimpleName (DeclBaseName::createConstructor ()) &&
2019
- !BaseType->getRValueType ()-> is <AnyMetatypeType>()) {
2019
+ !BaseType->is <AnyMetatypeType>()) {
2020
2020
if (auto ctorRef = dyn_cast<UnresolvedDotExpr>(getRawAnchor ())) {
2021
2021
if (isa<SuperRefExpr>(ctorRef->getBase ())) {
2022
2022
emitDiagnostic (loc, diag::super_initializer_not_in_initializer);
@@ -2063,8 +2063,8 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2063
2063
}
2064
2064
2065
2065
if (BaseType->is <AnyMetatypeType>() && !member->isStatic ()) {
2066
- auto instanceTy = BaseType-> getRValueType () ;
2067
-
2066
+ auto instanceTy = BaseType;
2067
+
2068
2068
if (auto *AMT = instanceTy->getAs <AnyMetatypeType>()) {
2069
2069
instanceTy = AMT->getInstanceType ();
2070
2070
}
@@ -2147,60 +2147,60 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2147
2147
// to replace the metatype with 'Self'
2148
2148
// error saying the lookup cannot be on a protocol metatype
2149
2149
Optional<InFlightDiagnostic> Diag;
2150
- auto baseObjTy = BaseType-> getRValueType () ;
2151
-
2152
- if (auto metatypeTy = baseObjTy ->getAs <MetatypeType >()) {
2150
+ auto baseTy = BaseType;
2151
+
2152
+ if (auto metatypeTy = baseTy ->getAs <AnyMetatypeType >()) {
2153
2153
auto instanceTy = metatypeTy->getInstanceType ();
2154
-
2154
+
2155
2155
// This will only happen if we have an unresolved dot expression
2156
2156
// (.foo) where foo is a protocol member and the contextual type is
2157
2157
// an optional protocol metatype.
2158
2158
if (auto objectTy = instanceTy->getOptionalObjectType ()) {
2159
2159
instanceTy = objectTy;
2160
- baseObjTy = MetatypeType::get (objectTy);
2160
+ baseTy = MetatypeType::get (objectTy);
2161
2161
}
2162
- assert (instanceTy->isExistentialType ());
2163
-
2164
- // Give a customized message if we're accessing a member type
2165
- // of a protocol -- otherwise a diagnostic talking about
2166
- // static members doesn't make a whole lot of sense
2167
- if (auto TAD = dyn_cast<TypeAliasDecl>(member)) {
2168
- Diag.emplace (emitDiagnostic (loc, diag::typealias_outside_of_protocol,
2169
- TAD->getName ()));
2170
- } else if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
2171
- Diag.emplace (emitDiagnostic (loc, diag::assoc_type_outside_of_protocol,
2172
- ATD->getName ()));
2173
- } else if (isa<ConstructorDecl>(member)) {
2174
- Diag.emplace (emitDiagnostic (loc, diag::construct_protocol_by_name,
2175
- instanceTy));
2176
- } else {
2177
- Diag.emplace (emitDiagnostic (loc,
2178
- diag::could_not_use_type_member_on_protocol_metatype,
2179
- baseObjTy, Name));
2180
- }
2181
-
2182
- Diag->highlight (baseRange).highlight (getAnchor ()->getSourceRange ());
2183
-
2184
- // See through function decl context
2185
- if (auto parent = cs.DC ->getInnermostTypeContext ()) {
2186
- // If we are in a protocol extension of 'Proto' and we see
2187
- // 'Proto.static', suggest 'Self.static'
2188
- if (auto extensionContext = parent->getExtendedProtocolDecl ()) {
2189
- if (extensionContext->getDeclaredType ()->isEqual (instanceTy)) {
2190
- Diag->fixItReplace (getAnchor ()->getSourceRange (), " Self" );
2162
+
2163
+ if (instanceTy->isExistentialType ()) {
2164
+ // Give a customized message if we're accessing a member type
2165
+ // of a protocol -- otherwise a diagnostic talking about
2166
+ // static members doesn't make a whole lot of sense
2167
+ if (auto TAD = dyn_cast<TypeAliasDecl>(member)) {
2168
+ Diag.emplace (emitDiagnostic (loc, diag::typealias_outside_of_protocol,
2169
+ TAD->getName ()));
2170
+ } else if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
2171
+ Diag.emplace (emitDiagnostic (loc, diag::assoc_type_outside_of_protocol,
2172
+ ATD->getName ()));
2173
+ } else if (isa<ConstructorDecl>(member)) {
2174
+ Diag.emplace (emitDiagnostic (loc, diag::construct_protocol_by_name,
2175
+ instanceTy));
2176
+ } else {
2177
+ Diag.emplace (emitDiagnostic (
2178
+ loc, diag::could_not_use_type_member_on_protocol_metatype, baseTy,
2179
+ Name));
2180
+ }
2181
+
2182
+ Diag->highlight (baseRange).highlight (getAnchor ()->getSourceRange ());
2183
+
2184
+ // See through function decl context
2185
+ if (auto parent = cs.DC ->getInnermostTypeContext ()) {
2186
+ // If we are in a protocol extension of 'Proto' and we see
2187
+ // 'Proto.static', suggest 'Self.static'
2188
+ if (auto extensionContext = parent->getExtendedProtocolDecl ()) {
2189
+ if (extensionContext->getDeclaredType ()->isEqual (instanceTy)) {
2190
+ Diag->fixItReplace (getAnchor ()->getSourceRange (), " Self" );
2191
+ }
2191
2192
}
2192
2193
}
2194
+
2195
+ return true ;
2193
2196
}
2194
-
2195
- return true ;
2196
2197
}
2197
2198
2198
2199
// If this is a reference to a static member by one of the key path
2199
2200
// components, let's provide a tailored diagnostic and return because
2200
2201
// that is unsupported so there is no fix-it.
2201
2202
if (locator->isForKeyPathComponent ()) {
2202
- InvalidStaticMemberRefInKeyPath failure (expr, getConstraintSystem (),
2203
- member, locator);
2203
+ InvalidStaticMemberRefInKeyPath failure (expr, cs, member, locator);
2204
2204
return failure.diagnoseAsError ();
2205
2205
}
2206
2206
@@ -2209,13 +2209,13 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2209
2209
loc, diag::could_not_use_enum_element_on_instance, Name));
2210
2210
} else {
2211
2211
Diag.emplace (emitDiagnostic (
2212
- loc, diag::could_not_use_type_member_on_instance, baseObjTy , Name));
2212
+ loc, diag::could_not_use_type_member_on_instance, baseTy , Name));
2213
2213
}
2214
2214
2215
2215
Diag->highlight (getAnchor ()->getSourceRange ());
2216
2216
2217
2217
if (Name.isSimpleName (DeclBaseName::createConstructor ()) &&
2218
- !baseObjTy ->is <AnyMetatypeType>()) {
2218
+ !baseTy ->is <AnyMetatypeType>()) {
2219
2219
if (auto ctorRef = dyn_cast<UnresolvedDotExpr>(getRawAnchor ())) {
2220
2220
SourceRange fixItRng = ctorRef->getNameLoc ().getSourceRange ();
2221
2221
Diag->fixItInsert (fixItRng.Start , " type(of: " );
@@ -2233,7 +2233,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2233
2233
2234
2234
// Try to provide a fix-it that only contains a '.'
2235
2235
if (contextualType) {
2236
- if (baseObjTy ->isEqual (contextualType)) {
2236
+ if (baseTy ->isEqual (contextualType)) {
2237
2237
Diag->fixItInsert (loc, " ." );
2238
2238
return true ;
2239
2239
}
@@ -2263,7 +2263,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
2263
2263
// since the type can be inferred
2264
2264
Type secondArgType =
2265
2265
lastCS->getType (binaryExpr->getArg ()->getElement (1 ));
2266
- if (secondArgType->isEqual (baseObjTy )) {
2266
+ if (secondArgType->isEqual (baseTy )) {
2267
2267
Diag->fixItInsert (loc, " ." );
2268
2268
return true ;
2269
2269
}
0 commit comments