Skip to content

Commit 059db5c

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Extension type. Issue 53866. Allow the representation type to be the subtype of implemented extension type.
Bug: #53866 Change-Id: Ic3ac0556695c8ffbb8a4545777ea07a8b52c1e76 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332363 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent a096d44 commit 059db5c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,11 +1785,15 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
17851785
return;
17861786
}
17871787

1788+
final declaredRepresentation = declaredElement.representation.type;
1789+
if (typeSystem.isSubtypeOf(declaredRepresentation, type)) {
1790+
return;
1791+
}
1792+
17881793
// When `type` is an extension type.
17891794
if (type is InterfaceTypeImpl) {
17901795
final implementedRepresentation = type.representationType;
17911796
if (implementedRepresentation != null) {
1792-
final declaredRepresentation = declaredElement.representation.type;
17931797
if (!typeSystem.isSubtypeOf(
17941798
declaredRepresentation,
17951799
implementedRepresentation,
@@ -1810,14 +1814,11 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
18101814
}
18111815
}
18121816

1813-
final declaredRepresentation = declaredElement.representation.type;
1814-
if (!typeSystem.isSubtypeOf(declaredRepresentation, type)) {
1815-
_errorReporter.reportErrorForNode(
1816-
CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_NOT_SUPERTYPE,
1817-
node,
1818-
[type, declaredRepresentation],
1819-
);
1820-
}
1817+
_errorReporter.reportErrorForNode(
1818+
CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_NOT_SUPERTYPE,
1819+
node,
1820+
[type, declaredRepresentation],
1821+
);
18211822
}
18221823

18231824
void _visitIf(IfElementOrStatementImpl node) {

pkg/analyzer/test/src/diagnostics/extension_type_implements_representation_not_supertype_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ extension type B(S3 it) implements A {}
4444
class S1 {}
4545
class S2 extends S1 {}
4646
class S3 extends S2 {}
47+
''');
48+
}
49+
50+
test_supertype3() async {
51+
await assertNoErrorsInCode('''
52+
extension type V1(num _) {}
53+
extension type V2(int _) implements V1 {}
54+
extension type ET(V2 id) implements V1 {}
4755
''');
4856
}
4957
}

0 commit comments

Comments
 (0)