Migrate "c" directory language tests off @compile-error.

The "@compile-error" comment is an old not-great way of defining static
error tests.

See: https://github.com/dart-lang/sdk/issues/45634
Change-Id: I3e10209e78e48893d2f2df7f8af7963d319efd9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296405
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2023-04-20 19:10:58 +00:00 committed by Commit Queue
parent aef551ac35
commit d244eeb84c
12 changed files with 63 additions and 12 deletions

View file

@ -17,7 +17,11 @@ abstract class B extends A implements I {
// no problem.
}
class /*@compile-error=unspecified*/ C extends B {
class C extends B {
// ^
// [analyzer] COMPILE_TIME_ERROR.INVALID_IMPLEMENTATION_OVERRIDE
// [cfe] The implementation of 'foo' in the non-abstract class 'C' does not conform to its interface.
// However, there is a problem here because this class is concrete and doesn't
// override foo.
}

View file

@ -10,7 +10,10 @@ class A {
}
class B extends A {
/*@compile-error=unspecified*/ foo(a) {}
foo(a) {}
//^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE
// [cfe] The method 'B.foo' has more required arguments than those of overridden method 'A.foo'.
}
main() {

View file

@ -8,7 +8,11 @@ class Cake {
@pragma("vm:external-name", "Cake_BakeMeACake")
@JSName("Cake_BakeMeACake")
external const factory Cake.BakeMeACake(); /*@compile-error=unspecified*/
//^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
// ^
// [cfe] Couldn't find constructor 'JSName'.
external const factory Cake.BakeMeACake();
}
main() {

View file

@ -4,7 +4,10 @@
// Test that setters are not invokable in the initializer list.
class A {
A() : a = 499; /*@compile-error=unspecified*/
A() : a = 499;
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INITIALIZER_FOR_NON_EXISTENT_FIELD
// [cfe] 'a' isn't an instance field of this class.
set a(val) {}
}

View file

@ -6,7 +6,13 @@
class A {
factory A() {
foo(); /*@compile-error=unspecified*/
// ^
// [analyzer] COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY
// [cfe] A non-null value must be returned since the return type 'A' doesn't allow null.
foo();
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] Method not found: 'foo'.
}
}

View file

@ -19,7 +19,11 @@ abstract class B extends A implements I {
// no problem.
}
class /*@compile-error=unspecified*/ C extends B {
class C extends B {
// ^
// [analyzer] COMPILE_TIME_ERROR.INVALID_IMPLEMENTATION_OVERRIDE
// [cfe] The implementation of 'foo' in the non-abstract class 'C' does not conform to its interface.
// However, there is a problem here because this class is concrete and doesn't
// override foo.
}

View file

@ -12,7 +12,10 @@ class A {
}
class B extends A {
/*@compile-error=unspecified*/ foo(a) {}
foo(a) {}
//^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE
// [cfe] The method 'B.foo' has more required arguments than those of overridden method 'A.foo'.
}
main() {

View file

@ -15,11 +15,18 @@ import "package:expect/expect.dart";
typedef void F<T>(T t);
class A {
// ^
// [cfe] The non-abstract class 'A' is missing implementations for these members:
void foo(Object n);
//^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
}
class C implements A {
F<Object> /*@compile-error=unspecified*/ foo;
F<Object> foo;
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_FIELD_AND_METHOD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
class D<T> {

View file

@ -15,11 +15,18 @@ import "package:expect/expect.dart";
typedef void F<T>(T t);
class A {
// ^
// [cfe] The non-abstract class 'A' is missing implementations for these members:
void foo(Object n);
//^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
}
class C implements A {
F<Object> get /*@compile-error=unspecified*/ foo => bar(new D<int>());
F<Object> get foo => bar(new D<int>());
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_FIELD_AND_METHOD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
class D<T> {

View file

@ -10,7 +10,11 @@ class Cake {
@pragma("vm:external-name", "Cake_BakeMeACake")
@JSName("Cake_BakeMeACake")
external const factory Cake.BakeMeACake(); /*@compile-error=unspecified*/
//^^^^^^^^^^^^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_ANNOTATION
// ^
// [cfe] Couldn't find constructor 'JSName'.
external const factory Cake.BakeMeACake();
}
main() {

View file

@ -6,7 +6,10 @@
// @dart = 2.9
class A {
A() : a = 499; /*@compile-error=unspecified*/
A() : a = 499;
// ^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INITIALIZER_FOR_NON_EXISTENT_FIELD
// [cfe] 'a' isn't an instance field of this class.
set a(val) {}
}

View file

@ -8,7 +8,10 @@
class A {
factory A() {
foo(); /*@compile-error=unspecified*/
foo();
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] Method not found: 'foo'.
}
}