@@ -3049,29 +3049,35 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
3049
3049
}
3050
3050
3051
3051
void visitExtensionDecl (ExtensionDecl *ED) {
3052
+ // Produce any diagnostics for the extended type.
3053
+ auto extType = ED->getExtendedType ();
3054
+
3055
+ auto nominal = ED->getExtendedNominal ();
3056
+ if (nominal == nullptr ) {
3057
+ ED->setInvalid ();
3058
+ ED->diagnose (diag::non_nominal_extension, extType);
3059
+ return ;
3060
+ }
3061
+
3052
3062
TC.validateExtension (ED);
3053
3063
3054
3064
checkInheritanceClause (ED);
3055
3065
3056
- if (auto nominal = ED->getExtendedNominal ()) {
3057
- TC.validateDecl (nominal);
3058
-
3059
- // Check the raw values of an enum, since we might synthesize
3060
- // RawRepresentable while checking conformances on this extension.
3061
- if (auto enumDecl = dyn_cast<EnumDecl>(nominal)) {
3062
- if (enumDecl->hasRawType ())
3063
- checkEnumRawValues (TC, enumDecl);
3064
- }
3066
+ // Check the raw values of an enum, since we might synthesize
3067
+ // RawRepresentable while checking conformances on this extension.
3068
+ if (auto enumDecl = dyn_cast<EnumDecl>(nominal)) {
3069
+ if (enumDecl->hasRawType ())
3070
+ checkEnumRawValues (TC, enumDecl);
3071
+ }
3065
3072
3066
- // Only generic and protocol types are permitted to have
3067
- // trailing where clauses.
3068
- if (auto trailingWhereClause = ED->getTrailingWhereClause ()) {
3069
- if (!ED->getGenericParams () &&
3070
- !ED->isInvalid ()) {
3071
- ED->diagnose (diag::extension_nongeneric_trailing_where,
3072
- nominal->getFullName ())
3073
- .highlight (trailingWhereClause->getSourceRange ());
3074
- }
3073
+ // Only generic and protocol types are permitted to have
3074
+ // trailing where clauses.
3075
+ if (auto trailingWhereClause = ED->getTrailingWhereClause ()) {
3076
+ if (!ED->getGenericParams () &&
3077
+ !ED->isInvalid ()) {
3078
+ ED->diagnose (diag::extension_nongeneric_trailing_where,
3079
+ nominal->getFullName ())
3080
+ .highlight (trailingWhereClause->getSourceRange ());
3075
3081
}
3076
3082
}
3077
3083
@@ -4371,13 +4377,14 @@ static Type formExtensionInterfaceType(
4371
4377
// / Check the generic parameters of an extension, recursively handling all of
4372
4378
// / the parameter lists within the extension.
4373
4379
static GenericEnvironment *
4374
- checkExtensionGenericParams (TypeChecker &tc, ExtensionDecl *ext, Type type,
4380
+ checkExtensionGenericParams (TypeChecker &tc, ExtensionDecl *ext,
4375
4381
GenericParamList *genericParams) {
4376
4382
assert (!ext->getGenericEnvironment ());
4377
4383
4378
4384
// Form the interface type of the extension.
4379
4385
bool mustInferRequirements = false ;
4380
4386
SmallVector<std::pair<Type, Type>, 4 > sameTypeReqs;
4387
+ auto type = ext->getExtendedType ();
4381
4388
Type extInterfaceType =
4382
4389
formExtensionInterfaceType (tc, ext, type, genericParams, sameTypeReqs,
4383
4390
mustInferRequirements);
@@ -4488,10 +4495,6 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
4488
4495
4489
4496
DeclValidationRAII IBV (ext);
4490
4497
4491
- auto extendedType = evaluateOrDefault (Context.evaluator ,
4492
- ExtendedTypeRequest{ext},
4493
- ErrorType::get (ext->getASTContext ()));
4494
-
4495
4498
if (auto *nominal = ext->getExtendedNominal ()) {
4496
4499
// If this extension was not already bound, it means it is either in an
4497
4500
// inactive conditional compilation block, or otherwise (incorrectly)
@@ -4504,8 +4507,7 @@ void TypeChecker::validateExtension(ExtensionDecl *ext) {
4504
4507
validateDecl (nominal);
4505
4508
4506
4509
if (auto *genericParams = ext->getGenericParams ()) {
4507
- GenericEnvironment *env =
4508
- checkExtensionGenericParams (*this , ext, extendedType, genericParams);
4510
+ auto *env = checkExtensionGenericParams (*this , ext, genericParams);
4509
4511
ext->setGenericEnvironment (env);
4510
4512
}
4511
4513
}
0 commit comments