@@ -3037,11 +3037,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
3037
3037
// Produce any diagnostics for the extended type.
3038
3038
auto extType = ED->getExtendedType ();
3039
3039
3040
- auto nominal = ED->computeExtendedNominal ();
3040
+ auto * nominal = ED->getExtendedNominal ();
3041
3041
if (nominal == nullptr ) {
3042
3042
const bool wasAlreadyInvalid = ED->isInvalid ();
3043
3043
ED->setInvalid ();
3044
- if (extType && !extType->hasError () && extType->getAnyNominal ()) {
3044
+ if (!extType->hasError () && extType->getAnyNominal ()) {
3045
3045
// If we've got here, then we have some kind of extension of a prima
3046
3046
// fascie non-nominal type. This can come up when we're projecting
3047
3047
// typealiases out of bound generic types.
@@ -3051,22 +3051,30 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
3051
3051
//
3052
3052
// Offer to rewrite it to the underlying nominal type.
3053
3053
auto canExtType = extType->getCanonicalType ();
3054
- ED->diagnose (diag::invalid_nominal_extension, extType, canExtType)
3055
- .highlight (ED->getExtendedTypeRepr ()->getSourceRange ());
3056
- ED->diagnose (diag::invalid_nominal_extension_rewrite, canExtType)
3057
- .fixItReplace (ED->getExtendedTypeRepr ()->getSourceRange (),
3058
- canExtType->getString ());
3059
- } else if (!wasAlreadyInvalid) {
3054
+ if (canExtType.getPointer () != extType.getPointer ()) {
3055
+ ED->diagnose (diag::invalid_nominal_extension, extType, canExtType)
3056
+ .highlight (ED->getExtendedTypeRepr ()->getSourceRange ());
3057
+ ED->diagnose (diag::invalid_nominal_extension_rewrite, canExtType)
3058
+ .fixItReplace (ED->getExtendedTypeRepr ()->getSourceRange (),
3059
+ canExtType->getString ());
3060
+ return ;
3061
+ }
3062
+ }
3063
+
3064
+ if (!wasAlreadyInvalid) {
3060
3065
// If nothing else applies, fall back to a generic diagnostic.
3061
3066
ED->diagnose (diag::non_nominal_extension, extType);
3062
3067
}
3068
+
3063
3069
return ;
3064
3070
}
3065
3071
3066
- // Produce any diagnostics for the generic signature.
3067
- (void ) ED->getGenericSignature ();
3072
+ // Record a dependency from TypeCheckSourceFileRequest to
3073
+ // ExtendedNominalRequest, since the call to getExtendedNominal()
3074
+ // above doesn't record a dependency when reading a cached value.
3075
+ ED->computeExtendedNominal ();
3068
3076
3069
- if (extType && !extType->hasError ()) {
3077
+ if (!extType->hasError ()) {
3070
3078
// The first condition catches syntactic forms like
3071
3079
// protocol A & B { ... } // may be protocols or typealiases
3072
3080
// The second condition also looks through typealiases and catches
@@ -3082,9 +3090,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
3082
3090
extTypeNominal && extTypeNominal != nominal;
3083
3091
if (isa<CompositionTypeRepr>(extTypeRepr)
3084
3092
|| firstNominalIsNotMostSpecific) {
3085
- auto firstNominalType = nominal->getDeclaredType ();
3086
3093
auto diag = ED->diagnose (diag::composition_in_extended_type,
3087
- firstNominalType );
3094
+ nominal-> getDeclaredType () );
3088
3095
diag.highlight (extTypeRepr->getSourceRange ());
3089
3096
if (firstNominalIsNotMostSpecific) {
3090
3097
diag.flush ();
@@ -3095,19 +3102,22 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
3095
3102
mostSpecificProtocol->getString ());
3096
3103
} else {
3097
3104
diag.fixItReplace (extTypeRepr->getSourceRange (),
3098
- firstNominalType ->getString ());
3105
+ nominal-> getDeclaredType () ->getString ());
3099
3106
}
3100
3107
}
3101
3108
}
3102
3109
3110
+ // Produce any diagnostics for the generic signature.
3111
+ (void ) ED->getGenericSignature ();
3112
+
3103
3113
checkInheritanceClause (ED);
3104
3114
3105
3115
// Only generic and protocol types are permitted to have
3106
3116
// trailing where clauses.
3107
3117
if (auto trailingWhereClause = ED->getTrailingWhereClause ()) {
3108
3118
if (!ED->getGenericParams () && !ED->isInvalid ()) {
3109
3119
ED->diagnose (diag::extension_nongeneric_trailing_where,
3110
- nominal->getName ())
3120
+ nominal->getDeclaredType ())
3111
3121
.highlight (trailingWhereClause->getSourceRange ());
3112
3122
}
3113
3123
}
0 commit comments