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