diff --git a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart index 10261d1dce3..d867e08ccfa 100644 --- a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart +++ b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart @@ -1785,11 +1785,15 @@ class ResolutionVisitor extends RecursiveAstVisitor { return; } + final declaredRepresentation = declaredElement.representation.type; + if (typeSystem.isSubtypeOf(declaredRepresentation, type)) { + return; + } + // When `type` is an extension type. if (type is InterfaceTypeImpl) { final implementedRepresentation = type.representationType; if (implementedRepresentation != null) { - final declaredRepresentation = declaredElement.representation.type; if (!typeSystem.isSubtypeOf( declaredRepresentation, implementedRepresentation, @@ -1810,14 +1814,11 @@ class ResolutionVisitor extends RecursiveAstVisitor { } } - final declaredRepresentation = declaredElement.representation.type; - if (!typeSystem.isSubtypeOf(declaredRepresentation, type)) { - _errorReporter.reportErrorForNode( - CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_NOT_SUPERTYPE, - node, - [type, declaredRepresentation], - ); - } + _errorReporter.reportErrorForNode( + CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_NOT_SUPERTYPE, + node, + [type, declaredRepresentation], + ); } void _visitIf(IfElementOrStatementImpl node) { diff --git a/pkg/analyzer/test/src/diagnostics/extension_type_implements_representation_not_supertype_test.dart b/pkg/analyzer/test/src/diagnostics/extension_type_implements_representation_not_supertype_test.dart index 2544c35f429..aa85572e123 100644 --- a/pkg/analyzer/test/src/diagnostics/extension_type_implements_representation_not_supertype_test.dart +++ b/pkg/analyzer/test/src/diagnostics/extension_type_implements_representation_not_supertype_test.dart @@ -44,6 +44,14 @@ extension type B(S3 it) implements A {} class S1 {} class S2 extends S1 {} class S3 extends S2 {} +'''); + } + + test_supertype3() async { + await assertNoErrorsInCode(''' +extension type V1(num _) {} +extension type V2(int _) implements V1 {} +extension type ET(V2 id) implements V1 {} '''); } }