@@ -3026,9 +3026,11 @@ bool TypeChecker::isPassThroughTypealias(TypeAliasDecl *typealias,
30263026
30273027Type
30283028ExtendedTypeRequest::evaluate (Evaluator &eval, ExtensionDecl *ext) const {
3029- auto error = [&ext]() {
3029+ auto &ctx = ext->getASTContext ();
3030+
3031+ auto error = [&]() {
30303032 ext->setInvalid ();
3031- return ErrorType::get (ext-> getASTContext () );
3033+ return ErrorType::get (ctx );
30323034 };
30333035
30343036 // If we didn't parse a type, fill in an error type and bail out.
@@ -3052,6 +3054,15 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
30523054 if (extendedType->hasError ())
30533055 return error ();
30543056
3057+ auto &diags = ctx.Diags ;
3058+
3059+ // Cannot extend types who contain placeholders.
3060+ if (extendedType->hasPlaceholder ()) {
3061+ diags.diagnose (ext->getLoc (), diag::extension_placeholder)
3062+ .highlight (extendedRepr->getSourceRange ());
3063+ return error ();
3064+ }
3065+
30553066 // Hack to allow extending a generic typealias.
30563067 if (auto *unboundGeneric = extendedType->getAs <UnboundGenericType>()) {
30573068 if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(unboundGeneric->getDecl ())) {
@@ -3069,8 +3080,6 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
30693080 }
30703081 }
30713082
3072- auto &diags = ext->getASTContext ().Diags ;
3073-
30743083 // Cannot extend a metatype.
30753084 if (extendedType->is <AnyMetatypeType>()) {
30763085 diags.diagnose (ext->getLoc (), diag::extension_metatype, extendedType)
@@ -3087,13 +3096,6 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
30873096 return error ();
30883097 }
30893098
3090- // Cannot extend types who contain placeholders.
3091- if (extendedType->hasPlaceholder ()) {
3092- diags.diagnose (ext->getLoc (), diag::extension_placeholder)
3093- .highlight (extendedRepr->getSourceRange ());
3094- return error ();
3095- }
3096-
30973099 return extendedType;
30983100}
30993101
0 commit comments