Migrate "t" 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: I4c2840deffe5d790a22facebbcc8a02c1cb98020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296425
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2023-04-20 19:55:31 +00:00 committed by Commit Queue
parent 199feac353
commit 51fe275a62
24 changed files with 114 additions and 28 deletions

View file

@ -13,7 +13,10 @@ int get getter {
class Class {
method() {
getter++; /*@compile-error=unspecified*/
getter++;
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL
// [cfe] Setter not found: 'getter'.
}
}

View file

@ -13,7 +13,10 @@ final int getter = () {
class Class {
method() {
getter++; /*@compile-error=unspecified*/
getter++;
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL
// [cfe] Setter not found: 'getter'.
}
}

View file

@ -5,7 +5,10 @@
// Test that an unresolved method call at the top level creates a compile-
// time error.
var a = b(); /*@compile-error=unspecified*/
var a = b();
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'b'.
main() {
print(a);

View file

@ -5,7 +5,10 @@
// Test that an unresolved identifier at the top level causes a compile-time
// error.
var a = b; /*@compile-error=unspecified*/
var a = b;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
// [cfe] Undefined name 'b'.
main() {
print(a);

View file

@ -15,7 +15,11 @@ class A {
int foo(String x) => 499;
const a = const A(foo); /*@compile-error=unspecified*/
const a = const A(foo);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'.
main() {
a.f(499);

View file

@ -10,10 +10,14 @@ abstract class J<T> {}
abstract class I<T extends num> {}
class A</*@compile-error=unspecified*/T> implements I<T>, J<T> {}
class A<T> implements I<T>, J<T> {}
// ^
// [cfe] Type argument 'T' doesn't conform to the bound 'num' of the type variable 'T' on 'I'.
// ^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
// We are only interested in the instance creation, hence
// the result is assigned to `dynamic`.
dynamic a = /*@compile-error=unspecified*/ new A<String>();
dynamic a = new A<String>();
}

View file

@ -11,7 +11,10 @@ class A {
class B<T> {
doFunc() {
T.func(); /*@compile-error=unspecified*/
T.func();
//^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'func' isn't defined for the class 'Type'.
}
}

View file

@ -8,7 +8,10 @@ import "package:expect/expect.dart";
class Foo<T> {
// T is not in scope for a static method.
static Foo<T> m() { /*@compile-error=unspecified*/
static Foo<T> m() {
// ^
// [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC
// [cfe] Type variables can't be used in static members.
return new Foo();
}
}

View file

@ -6,9 +6,16 @@
class A<T> {
static int method() {
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.BODY_MIGHT_COMPLETE_NORMALLY
// [cfe] A non-null value must be returned since the return type 'int' doesn't allow null.
// error, can't reference a type variable in a static context
var foo =
new T(); /*@compile-error=unspecified*/
var foo = new T();
// ^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC
// [cfe] Couldn't find constructor 'T'.
}
}

View file

@ -6,7 +6,11 @@
typedef F<T extends num> = T Function<U>(T x);
void g(/*@compile-error=unspecified*/ F<String>? f) {}
void g(F<String>? f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);

View file

@ -6,7 +6,11 @@
typedef T F<T extends num>(T x);
void g(/*@compile-error=unspecified*/ F<String>? f) {}
void g(F<String>? f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);

View file

@ -7,7 +7,11 @@
typedef void F<T extends num>();
void g(/*@compile-error=unspecified*/ F<String>? f) {}
void g(F<String>? f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);

View file

@ -14,7 +14,10 @@ int get getter {
class Class {
method() {
getter++; /*@compile-error=unspecified*/
getter++;
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL
// [cfe] Setter not found: 'getter'.
}
}

View file

@ -14,7 +14,10 @@ final int getter = () {
class Class {
method() {
getter++; /*@compile-error=unspecified*/
getter++;
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL
// [cfe] Setter not found: 'getter'.
}
}

View file

@ -7,7 +7,10 @@
// Test that an unresolved method call at the top level creates a compile-
// time error.
var a = b(); /*@compile-error=unspecified*/
var a = b();
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'b'.
main() {
print(a);

View file

@ -7,7 +7,10 @@
// Test that an unresolved identifier at the top level causes a compile-time
// error.
var a = b; /*@compile-error=unspecified*/
var a = b;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_IDENTIFIER
// [cfe] Undefined name 'b'.
main() {
print(a);

View file

@ -17,7 +17,11 @@ class A {
int foo(String x) => 499;
const a = const A(foo); /*@compile-error=unspecified*/
const a = const A(foo);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH
// [cfe] The argument type 'int Function(String)' can't be assigned to the parameter type 'String Function(int)'.
main() {
a.f(499);

View file

@ -12,10 +12,14 @@ abstract class J<T> {}
abstract class I<T extends num> {}
class A</*@compile-error=unspecified*/T> implements I<T>, J<T> {}
class A<T> implements I<T>, J<T> {}
// ^
// [cfe] Type argument 'T' doesn't conform to the bound 'num' of the type variable 'T' on 'I'.
// ^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
// We are only interested in the instance creation, hence
// the result is assigned to `dynamic`.
dynamic a = /*@compile-error=unspecified*/ new A<String>();
dynamic a = new A<String>();
}

View file

@ -13,7 +13,10 @@ class A {
class B<T> {
doFunc() {
T.func(); /*@compile-error=unspecified*/
T.func();
//^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_METHOD
// [cfe] The method 'func' isn't defined for the class 'Type'.
}
}

View file

@ -10,7 +10,10 @@ import "package:expect/expect.dart";
class Foo<T> {
// T is not in scope for a static method.
static Foo<T> m() { /*@compile-error=unspecified*/
static Foo<T> m() {
// ^
// [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC
// [cfe] Type variables can't be used in static members.
return new Foo();
}
}

View file

@ -9,8 +9,11 @@
class A<T> {
static int method() {
// error, can't reference a type variable in a static context
var foo =
new T(); /*@compile-error=unspecified*/
var foo = new T();
// ^
// [analyzer] COMPILE_TIME_ERROR.CREATION_WITH_NON_TYPE
// [analyzer] COMPILE_TIME_ERROR.TYPE_PARAMETER_REFERENCED_BY_STATIC
// [cfe] Couldn't find constructor 'T'.
}
}

View file

@ -8,7 +8,11 @@
typedef F<T extends num> = T Function<U>(T x);
void g(/*@compile-error=unspecified*/ F<String> f) {}
void g(F<String> f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);

View file

@ -8,7 +8,11 @@
typedef T F<T extends num>(T x);
void g(/*@compile-error=unspecified*/ F<String> f) {}
void g(F<String> f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);

View file

@ -9,7 +9,11 @@
typedef void F<T extends num>();
void g(/*@compile-error=unspecified*/ F<String> f) {}
void g(F<String> f) {}
// ^
// [cfe] Type argument 'String' doesn't conform to the bound 'num' of the type variable 'T' on 'F'.
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
main() {
g(null);