mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Sema] Check for placeholders in extended type first
Avoid emitting a diagnostic about `<<hole>>` being a non-nominal type.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user