@@ -1131,21 +1131,26 @@ static Type diagnoseUnknownType(TypeResolution resolution,
1131
1131
NominalTypeDecl *nominal = nullptr ;
1132
1132
if ((nominalDC = dc->getInnermostTypeContext ()) &&
1133
1133
(nominal = nominalDC->getSelfNominalTypeDecl ())) {
1134
- // Attempt to refer to 'Self' within a non-protocol nominal
1135
- // type. Fix this by replacing 'Self' with the nominal type name.
1136
- assert (isa<ClassDecl>(nominal) && " Must be a class " );
1134
+ if (isa<ClassDecl>( nominal)) {
1135
+ // Attempt to refer to 'Self' within a non-protocol nominal
1136
+ // type. Fix this by replacing 'Self' with the nominal type name.
1137
1137
1138
- // Produce a Fix-It replacing 'Self' with the nominal type name.
1139
- auto name = getDeclNameFromContext (dc, nominal);
1140
- diags.diagnose (comp->getNameLoc (), diag::dynamic_self_invalid, name)
1141
- .fixItReplace (comp->getNameLoc ().getSourceRange (), name);
1138
+ // Produce a Fix-It replacing 'Self' with the nominal type name.
1139
+ auto name = getDeclNameFromContext (dc, nominal);
1140
+ diags.diagnose (comp->getNameLoc (), diag::dynamic_self_invalid, name)
1141
+ .fixItReplace (comp->getNameLoc ().getSourceRange (), name);
1142
1142
1143
- auto type = resolution.mapTypeIntoContext (
1144
- dc->getInnermostTypeContext ()->getSelfInterfaceType ());
1143
+ auto type = resolution.mapTypeIntoContext (
1144
+ dc->getInnermostTypeContext ()->getSelfInterfaceType ());
1145
1145
1146
- comp->overwriteNameRef (DeclNameRef (nominal->getName ()));
1147
- comp->setValue (nominal, nominalDC->getParent ());
1148
- return type;
1146
+ comp->overwriteNameRef (DeclNameRef (nominal->getName ()));
1147
+ comp->setValue (nominal, nominalDC->getParent ());
1148
+ return type;
1149
+ } else {
1150
+ diags.diagnose (comp->getNameLoc (), diag::cannot_find_type_in_scope,
1151
+ comp->getNameRef ());
1152
+ return ErrorType::get (ctx);
1153
+ }
1149
1154
}
1150
1155
// Attempt to refer to 'Self' from a free function.
1151
1156
diags.diagnose (comp->getNameLoc (), diag::dynamic_self_non_method,
0 commit comments