@@ -1746,12 +1746,11 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
1746
1746
null ,
1747
1747
);
1748
1748
_checkForClassUsedAsMixin (withClause);
1749
- _checkForSealedSupertypeOutsideOfLibrary (
1750
- superclass,
1751
- withClause,
1752
- implementsClause,
1753
- null ,
1754
- );
1749
+ _checkForSealedSupertypeOutsideOfLibrary ([
1750
+ if (superclass != null ) superclass,
1751
+ ...? withClause? .mixinTypes,
1752
+ ...? implementsClause? .interfaces,
1753
+ ]);
1755
1754
return true ;
1756
1755
}
1757
1756
return false ;
@@ -5214,46 +5213,22 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
5214
5213
);
5215
5214
}
5216
5215
5217
- /// Check that if a direct supertype of a node is sealed, then it must be in
5218
- /// the same library.
5216
+ /// Checks that every supertype which is sealed is also declared in the
5217
+ /// current library.
5219
5218
///
5220
5219
/// See [CompileTimeErrorCode.SEALED_CLASS_SUBTYPE_OUTSIDE_OF_LIBRARY] .
5221
- void _checkForSealedSupertypeOutsideOfLibrary (
5222
- NamedType ? superclass,
5223
- WithClause ? withClause,
5224
- ImplementsClause ? implementsClause,
5225
- MixinOnClause ? onClause,
5226
- ) {
5227
- void reportErrorsForSealedClassesAndMixins (List <NamedType > namedTypes) {
5228
- for (NamedType namedType in namedTypes) {
5229
- var type = namedType.type;
5230
- if (type is InterfaceType ) {
5231
- var element = type.element;
5232
- if (element is ClassElement &&
5233
- element.isSealed &&
5234
- element.library != _currentLibrary) {
5235
- diagnosticReporter.atNode (
5236
- namedType,
5237
- CompileTimeErrorCode .SEALED_CLASS_SUBTYPE_OUTSIDE_OF_LIBRARY ,
5238
- arguments: [element.name! ],
5239
- );
5240
- }
5220
+ void _checkForSealedSupertypeOutsideOfLibrary (List <NamedType > supertypes) {
5221
+ for (NamedType namedType in supertypes) {
5222
+ if (namedType.type case InterfaceType (: ClassElement element)) {
5223
+ if (element.isSealed && element.library != _currentLibrary) {
5224
+ diagnosticReporter.atNode (
5225
+ namedType,
5226
+ CompileTimeErrorCode .SEALED_CLASS_SUBTYPE_OUTSIDE_OF_LIBRARY ,
5227
+ arguments: [element.name! ],
5228
+ );
5241
5229
}
5242
5230
}
5243
5231
}
5244
-
5245
- if (superclass != null ) {
5246
- reportErrorsForSealedClassesAndMixins ([superclass]);
5247
- }
5248
- if (withClause != null ) {
5249
- reportErrorsForSealedClassesAndMixins (withClause.mixinTypes);
5250
- }
5251
- if (implementsClause != null ) {
5252
- reportErrorsForSealedClassesAndMixins (implementsClause.interfaces);
5253
- }
5254
- if (onClause != null ) {
5255
- reportErrorsForSealedClassesAndMixins (onClause.superclassConstraints);
5256
- }
5257
5232
}
5258
5233
5259
5234
/// Verify that the elements in the given set [literal] are subtypes of the
@@ -6067,12 +6042,10 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
6067
6042
implementsClause,
6068
6043
onClause,
6069
6044
);
6070
- _checkForSealedSupertypeOutsideOfLibrary (
6071
- null ,
6072
- null ,
6073
- implementsClause,
6074
- onClause,
6075
- );
6045
+ _checkForSealedSupertypeOutsideOfLibrary ([
6046
+ ...? implementsClause? .interfaces,
6047
+ ...? onClause? .superclassConstraints,
6048
+ ]);
6076
6049
}
6077
6050
}
6078
6051
0 commit comments