1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-08 12:06:26 +00:00

Extension types. Report CONFLICTING_METHOD_AND_FIELD and CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD.

Change-Id: I3ebf1f2f767f2b64cf47e2c80473b086695d20d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319869
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-08-10 22:54:26 +00:00 committed by Commit Queue
parent 42b992c947
commit f6db810b96
4 changed files with 20 additions and 14 deletions

View File

@ -2046,8 +2046,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
name,
inherited.enclosingElement.displayName,
]);
} else if (inherited is PropertyAccessorElement &&
_enclosingClass is! ExtensionTypeElement) {
} else if (inherited is PropertyAccessorElement) {
errorReporter.reportErrorForElement(
CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, method, [
_enclosingClass!.displayName,
@ -2074,8 +2073,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
name,
inherited.enclosingElement.displayName,
]);
} else if (inherited is MethodElement &&
_enclosingClass is! ExtensionTypeElement) {
} else if (inherited is MethodElement) {
errorReporter.reportErrorForElement(
CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, accessor, [
_enclosingClass!.displayName,

View File

@ -100,7 +100,7 @@ enum E with M {
}
test_extensionType_getter() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
extension type A(int it) {
void foo() {}
}
@ -108,11 +108,13 @@ extension type A(int it) {
extension type B(int it) implements A {
int get foo => 0;
}
''');
''', [
error(CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, 96, 3),
]);
}
test_extensionType_setter() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
extension type A(int it) {
void foo() {}
}
@ -120,6 +122,8 @@ extension type A(int it) {
extension type B(int it) implements A {
set foo(int _) {}
}
''');
''', [
error(CompileTimeErrorCode.CONFLICTING_FIELD_AND_METHOD, 92, 3),
]);
}
}

View File

@ -85,7 +85,7 @@ enum E with M {
}
test_extensionType_getter() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
extension type A(int it) {
int get foo => 0;
}
@ -93,11 +93,13 @@ extension type A(int it) {
extension type B(int it) implements A {
void foo() {}
}
''');
''', [
error(CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, 97, 3),
]);
}
test_extensionType_setter() async {
await assertNoErrorsInCode(r'''
await assertErrorsInCode(r'''
extension type A(int it) {
set foo(int _) {}
}
@ -105,6 +107,8 @@ extension type A(int it) {
extension type B(int it) implements A {
void foo() {}
}
''');
''', [
error(CompileTimeErrorCode.CONFLICTING_METHOD_AND_FIELD, 97, 3),
]);
}
}

View File

@ -18,11 +18,11 @@ class ExtensionTypeDeclaresMemberOfObjectTest extends PubPackageResolutionTest {
test_instance_differentKind() async {
await assertErrorsInCode('''
extension type E(int it) {
void hashCode() {}
int get hashCode => 0;
}
''', [
error(
CompileTimeErrorCode.EXTENSION_TYPE_DECLARES_MEMBER_OF_OBJECT, 34, 8),
CompileTimeErrorCode.EXTENSION_TYPE_DECLARES_MEMBER_OF_OBJECT, 37, 8),
]);
}