@@ -1130,21 +1130,26 @@ static Type diagnoseUnknownType(TypeResolution resolution,
11301130 NominalTypeDecl *nominal = nullptr ;
11311131 if ((nominalDC = dc->getInnermostTypeContext ()) &&
11321132 (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.
11361136
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);
11411141
1142- auto type = resolution.mapTypeIntoContext (
1143- dc->getInnermostTypeContext ()->getSelfInterfaceType ());
1142+ auto type = resolution.mapTypeIntoContext (
1143+ dc->getInnermostTypeContext ()->getSelfInterfaceType ());
11441144
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+ }
11481153 }
11491154 // Attempt to refer to 'Self' from a free function.
11501155 diags.diagnose (comp->getNameLoc (), diag::dynamic_self_non_method,
0 commit comments