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

View file

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

View file

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