[Sema] Check for placeholders in extended type first

Avoid emitting a diagnostic about `<<hole>>` being a non-nominal type.
This commit is contained in:
Hamish Knight
2025-09-17 15:23:08 +01:00
parent 75d60b3484
commit 71f8e68655
2 changed files with 15 additions and 11 deletions

View File

@@ -3026,9 +3026,11 @@ bool TypeChecker::isPassThroughTypealias(TypeAliasDecl *typealias,
Type
ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
auto error = [&ext]() {
auto &ctx = ext->getASTContext();
auto error = [&]() {
ext->setInvalid();
return ErrorType::get(ext->getASTContext());
return ErrorType::get(ctx);
};
// 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 {
if (extendedType->hasError())
return error();
auto &diags = ctx.Diags;
// Cannot extend types who contain placeholders.
if (extendedType->hasPlaceholder()) {
diags.diagnose(ext->getLoc(), diag::extension_placeholder)
.highlight(extendedRepr->getSourceRange());
return error();
}
// Hack to allow extending a generic typealias.
if (auto *unboundGeneric = extendedType->getAs<UnboundGenericType>()) {
if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(unboundGeneric->getDecl())) {
@@ -3069,8 +3080,6 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
}
}
auto &diags = ext->getASTContext().Diags;
// Cannot extend a metatype.
if (extendedType->is<AnyMetatypeType>()) {
diags.diagnose(ext->getLoc(), diag::extension_metatype, extendedType)
@@ -3087,13 +3096,6 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const {
return error();
}
// Cannot extend types who contain placeholders.
if (extendedType->hasPlaceholder()) {
diags.diagnose(ext->getLoc(), diag::extension_placeholder)
.highlight(extendedRepr->getSourceRange());
return error();
}
return extendedType;
}

View File

@@ -402,3 +402,5 @@ extension BitwiseCopyable {} // expected-error {{cannot extend protocol 'Bitwise
@_marker protocol MyMarkerProto {}
extension MyMarkerProto {} // OK
extension _ {} // expected-error {{cannot extend a type that contains placeholders}}