Extension type. Issue 53866. Allow the representation type to be the subtype of implemented extension type.

Bug: https://github.com/dart-lang/sdk/issues/53866
Change-Id: Ic3ac0556695c8ffbb8a4545777ea07a8b52c1e76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332363
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-10-26 19:23:11 +00:00 committed by Commit Queue
parent a096d44753
commit 059db5cb97
2 changed files with 18 additions and 9 deletions

View file

@ -1785,11 +1785,15 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
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<void> {
}
}
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) {

View file

@ -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 {}
''');
}
}