Migrate "r" 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: I5dd012381390ef2c00d674308db3fe099ecc6a4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296423
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Nate Bosch <nbosch@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-19 23:35:16 +00:00 committed by Commit Queue
parent 6dcca7824a
commit 27ef9f0762
36 changed files with 246 additions and 52 deletions

View file

@ -5,9 +5,17 @@
import "package:expect/expect.dart";
class C {
noSuchMethod(int x, int y) => x + y; /*@compile-error=unspecified*/
noSuchMethod(int x, int y) => x + y;
//^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE
// [cfe] The method 'C.noSuchMethod' has more required arguments than those of overridden method 'Object.noSuchMethod'.
// ^
// [cfe] The parameter 'x' of the method 'C.noSuchMethod' has type 'int', which does not match the corresponding type, 'Invocation', in the overridden method, 'Object.noSuchMethod'.
}
main() {
Expect.throws(() => new C().foo, (e) => e is Error); /*@compile-error=unspecified*/
Expect.throws(() => new C().foo, (e) => e is Error);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] The getter 'foo' isn't defined for the class 'C'.
}

View file

@ -16,7 +16,10 @@ class A {}
main() {
bool caught = false;
try {
A.unknown = p(2); /*@compile-error=unspecified*/
A.unknown = p(2);
//^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_SETTER
// [cfe] Setter not found: 'unknown'.
} catch (_) {
caught = true;
}

View file

@ -15,7 +15,10 @@ m(x) {
main() {
try {
tl(m(0)); /*@compile-error=unspecified*/
tl(m(0));
// ^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'tl'.
} catch (e) {}
Expect.isTrue(mCalled);
}

View file

@ -8,5 +8,8 @@ import 'regress19413_foo.dart' as foo;
import 'regress19413_bar.dart' as foo;
main() {
foo.f(); /*@compile-error=unspecified*/
foo.f();
// ^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_IMPORT
// [cfe] 'f' is imported from both 'tests/language/regress/regress19413_bar.dart' and 'tests/language/regress/regress19413_foo.dart'.
}

View file

@ -8,8 +8,14 @@ class C<T extends dynamic> {
T? field;
test() {
field = 0; /*@compile-error=unspecified*/
int i = field; /*@compile-error=unspecified*/
field = 0;
// ^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'int' can't be assigned to a variable of type 'T?'.
int i = field;
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'T?' can't be assigned to a variable of type 'int'.
}
}

View file

@ -10,7 +10,10 @@ main() async {
try {
try {
await new Future.error("error");
} on MissingType catch (e) {} /*@compile-error=unspecified*/
} on MissingType catch (e) {}
// ^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_TYPE_IN_CATCH_CLAUSE
// [cfe] 'MissingType' isn't a type.
} catch (e) {
error = e;
}

View file

@ -16,7 +16,10 @@ foo() {
main() {
final x = null;
try {
x = /*@compile-error=unspecified*/ foo();
x = foo();
// ^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_LOCAL
// [cfe] Can't assign to the final variable 'x'.
} on NoSuchMethodError {}
Expect.isTrue(fooCalled);
}

View file

@ -6,18 +6,43 @@
// Generic bounds now must be fully instantiated. This means that the
// cycle is not possible anymore.
abstract class IPeer<C extends IP2PClient /*@compile-error=unspecified*/ > {}
abstract class IPeer<C extends IP2PClient> {}
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
abstract class IPeerRoom<P extends IPeer, C extends IP2PClient> {}
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
abstract class IP2PClient<R extends IPeerRoom> {}
// ^
// [cfe] Generic type 'IP2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through 'IPeerRoom'.
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class _Peer<C extends _P2PClient> implements IPeer<C> {}
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class _PeerRoom<P extends _Peer, C extends _P2PClient>
implements IPeerRoom<P, C> {}
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
implements
IPeerRoom<P, C> {}
abstract class _P2PClient<R extends _PeerRoom, P extends _Peer>
implements IP2PClient<R> {}
// ^
// [cfe] Generic type '_P2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through '_Peer'.
// [cfe] Generic type '_P2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through '_PeerRoom'.
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
implements
IP2PClient<R> {}
void main() {}

View file

@ -7,7 +7,10 @@ import 'dart:async';
var x = 'a';
Future<int> foo() async {
return x; /*@compile-error=unspecified*/
return x;
// ^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'String' can't be returned from an async function with return type 'Future<int>'.
}
main() {

View file

@ -10,5 +10,8 @@ import "package:expect/expect.dart";
import 'dart:collection' as col;
main() {
col.foobar(1234567); /*@compile-error=unspecified*/
col.foobar(1234567);
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'foobar'.
}

View file

@ -6,5 +6,10 @@ void main() {
int Function(int) f;
List<num> l = [];
/*@compile-error=unspecified*/ var a = l.map(f);
var a = l.map(f);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [analyzer] COMPILE_TIME_ERROR.NOT_ASSIGNED_POTENTIALLY_NON_NULLABLE_LOCAL_VARIABLE
// [cfe] Non-nullable variable 'f' must be assigned before it can be used.
// [cfe] The argument type 'int Function(int)' can't be assigned to the parameter type 'dynamic Function(num)'.
}

View file

@ -15,6 +15,11 @@ class B<X, Y> {}
mixin C<X> on B<X, A> {}
class /*@compile-error=unspecified*/ D<X, Y> extends B<X, Y> with C {}
class D<X, Y> extends B<X, Y> with C {}
// ^
// [cfe] 'B with C' can't implement both 'B<X, Y>' and 'B<dynamic, A>'
// [cfe] 'B<X, Y>' doesn't implement 'B<dynamic, A>' so it can't be used with 'C<dynamic>'.
// ^
// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NOT_IMPLEMENTED_INTERFACE
main() {}

View file

@ -6,7 +6,10 @@ import 'dart:core';
import 'dart:core' as core;
class A {
/*@compile-error=unspecified*/ core.List get core => throw "uncalled";
core.List get core => throw "uncalled";
//^^^^
// [analyzer] COMPILE_TIME_ERROR.PREFIX_SHADOWED_BY_LOCAL_DECLARATION
// [cfe] 'core.List' can't be used as a type because 'core' doesn't refer to an import prefix.
}
main() {

View file

@ -6,5 +6,8 @@
var x = (() => 1)();
main() {
/*@compile-error=unspecified*/ x = 'bad'; // `String` not assignable to `int`
x = 'bad'; // `String` not assignable to `int`
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
}

View file

@ -7,6 +7,9 @@ class Foo<T> {}
class Bar<T extends Foo<T>> {}
// Should be error here, because Bar completes to Bar<Foo>
class Baz extends /*@compile-error=unspecified*/ Bar {}
class Baz extends Bar {}
// ^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
// [cfe] Inferred type argument 'Foo<dynamic>' doesn't conform to the bound 'Foo<T>' of the type variable 'T' on 'Bar'.
void main() {}

View file

@ -2,8 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class /*@compile-error=unspecified*/ A<X extends C> {}
class A<X extends C> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ C<X extends C> {}
class C<X extends C> {}
// ^
// [cfe] Generic type 'C' can't be used without type arguments in the bounds of its own type variables.
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
main() {}

View file

@ -2,10 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class /*@compile-error=unspecified*/ A<X extends B> {}
class A<X extends B> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ B<X extends C> {}
class B<X extends C> {}
// ^
// [cfe] Generic type 'B' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through 'C'.
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ C<X extends A<B>> {}
class C<X extends A<B>> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
main() {}

View file

@ -4,9 +4,14 @@
import "package:expect/expect.dart";
int returnString1() => 's'; /*@compile-error=unspecified*/
int returnString1() => 's';
// ^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'String' can't be returned from a function with return type 'int'.
// OK to return anything from a void function with a "=>" body.
void returnNull() => null;
void returnString2() => 's'; /*@compile-error=unspecified*/
void returnString2() => 's';
main() {
returnString1();

View file

@ -7,9 +7,17 @@
import "package:expect/expect.dart";
class C {
noSuchMethod(int x, int y) => x + y; /*@compile-error=unspecified*/
noSuchMethod(int x, int y) => x + y;
//^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_OVERRIDE
// [cfe] The method 'C.noSuchMethod' has more required arguments than those of overridden method 'Object.noSuchMethod'.
// ^
// [cfe] The parameter 'x' of the method 'C.noSuchMethod' has type 'int', which does not match the corresponding type, 'Invocation', in the overridden method, 'Object.noSuchMethod'.
}
main() {
Expect.throws(() => new C().foo, (e) => e is Error); /*@compile-error=unspecified*/
Expect.throws(() => new C().foo, (e) => e is Error);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] The getter 'foo' isn't defined for the class 'C'.
}

View file

@ -18,7 +18,10 @@ class A {}
main() {
bool caught = false;
try {
A.unknown = p(2); /*@compile-error=unspecified*/
A.unknown = p(2);
//^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_SETTER
// [cfe] Setter not found: 'unknown'.
} catch (_) {
caught = true;
}

View file

@ -17,7 +17,10 @@ m(x) {
main() {
try {
tl(m(0)); /*@compile-error=unspecified*/
tl(m(0));
// ^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'tl'.
} catch (e) {}
Expect.isTrue(mCalled);
}

View file

@ -10,5 +10,8 @@ import 'regress19413_foo.dart' as foo;
import 'regress19413_bar.dart' as foo;
main() {
foo.f(); /*@compile-error=unspecified*/
foo.f();
// ^
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_IMPORT
// [cfe] 'f' is imported from both 'tests/language_2/regress/regress19413_bar.dart' and 'tests/language_2/regress/regress19413_foo.dart'.
}

View file

@ -10,8 +10,14 @@ class C<T extends dynamic> {
T field;
test() {
field = 0; /*@compile-error=unspecified*/
int i = field; /*@compile-error=unspecified*/
field = 0;
// ^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'int' can't be assigned to a variable of type 'T'.
int i = field;
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'T' can't be assigned to a variable of type 'int'.
}
}

View file

@ -12,7 +12,10 @@ main() async {
try {
try {
await new Future.error("error");
} on MissingType catch (e) {} /*@compile-error=unspecified*/
} on MissingType catch (e) {}
// ^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_TYPE_IN_CATCH_CLAUSE
// [cfe] 'MissingType' isn't a type.
} catch (e) {
error = e;
}

View file

@ -18,7 +18,10 @@ foo() {
main() {
final x = null;
try {
x = /*@compile-error=unspecified*/ foo();
x = foo();
// ^
// [analyzer] COMPILE_TIME_ERROR.ASSIGNMENT_TO_FINAL_LOCAL
// [cfe] Can't assign to the final variable 'x'.
} on NoSuchMethodError {}
Expect.isTrue(fooCalled);
}

View file

@ -8,18 +8,43 @@
// Generic bounds now must be fully instantiated. This means that the
// cycle is not possible anymore.
abstract class IPeer<C extends IP2PClient /*@compile-error=unspecified*/ > {}
abstract class IPeer<C extends IP2PClient> {}
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
abstract class IPeerRoom<P extends IPeer, C extends IP2PClient> {}
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
abstract class IP2PClient<R extends IPeerRoom> {}
// ^
// [cfe] Generic type 'IP2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through 'IPeerRoom'.
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class _Peer<C extends _P2PClient> implements IPeer<C> {}
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class _PeerRoom<P extends _Peer, C extends _P2PClient>
implements IPeerRoom<P, C> {}
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
implements
IPeerRoom<P, C> {}
abstract class _P2PClient<R extends _PeerRoom, P extends _Peer>
implements IP2PClient<R> {}
// ^
// [cfe] Generic type '_P2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through '_Peer'.
// [cfe] Generic type '_P2PClient' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through '_PeerRoom'.
// ^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
implements
IP2PClient<R> {}
void main() {}

View file

@ -9,7 +9,10 @@ import 'dart:async';
var x = 'a';
Future<int> foo() async {
return x; /*@compile-error=unspecified*/
return x;
// ^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'Future<String>' can't be assigned to a variable of type 'FutureOr<int>'.
}
main() {

View file

@ -12,5 +12,8 @@ import "package:expect/expect.dart";
import 'dart:collection' as col;
main() {
col.foobar(1234567); /*@compile-error=unspecified*/
col.foobar(1234567);
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_FUNCTION
// [cfe] Method not found: 'foobar'.
}

View file

@ -8,5 +8,8 @@ void main() {
int Function(int) f;
List<num> l = [];
/*@compile-error=unspecified*/ var a = l.map(f);
var a = l.map(f);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int Function(int)' can't be assigned to the parameter type 'dynamic Function(num)'.
}

View file

@ -17,6 +17,11 @@ class B<X, Y> {}
mixin C<X> on B<X, A> {}
class /*@compile-error=unspecified*/ D<X, Y> extends B<X, Y> with C {}
class D<X, Y> extends B<X, Y> with C {}
// ^
// [cfe] 'B with C' can't implement both 'B<X, Y>' and 'B<dynamic, A>'
// [cfe] 'B<X, Y>' doesn't implement 'B<dynamic, A>' so it can't be used with 'C<dynamic>'.
// ^
// [analyzer] COMPILE_TIME_ERROR.MIXIN_APPLICATION_NOT_IMPLEMENTED_INTERFACE
main() {}

View file

@ -8,7 +8,10 @@ import 'dart:core';
import 'dart:core' as core;
class A {
/*@compile-error=unspecified*/ core.List get core => null;
core.List get core => null;
//^^^^
// [analyzer] COMPILE_TIME_ERROR.PREFIX_SHADOWED_BY_LOCAL_DECLARATION
// [cfe] 'core.List' can't be used as a type because 'core' doesn't refer to an import prefix.
}
main() {

View file

@ -8,5 +8,8 @@
var x = (() => 1)();
main() {
/*@compile-error=unspecified*/ x = 'bad'; // `String` not assignable to `int`
x = 'bad'; // `String` not assignable to `int`
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_ASSIGNMENT
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
}

View file

@ -9,6 +9,9 @@ class Foo<T> {}
class Bar<T extends Foo<T>> {}
// Should be error here, because Bar completes to Bar<Foo>
class Baz extends /*@compile-error=unspecified*/ Bar {}
class Baz extends Bar {}
// ^^^
// [analyzer] COMPILE_TIME_ERROR.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS
// [cfe] Inferred type argument 'Foo<dynamic>' doesn't conform to the bound 'Foo<T>' of the type variable 'T' on 'Bar'.
void main() {}

View file

@ -4,8 +4,14 @@
// @dart = 2.9
class /*@compile-error=unspecified*/ A<X extends C> {}
class A<X extends C> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ C<X extends C> {}
class C<X extends C> {}
// ^
// [cfe] Generic type 'C' can't be used without type arguments in the bounds of its own type variables.
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
main() {}

View file

@ -4,10 +4,18 @@
// @dart = 2.9
class /*@compile-error=unspecified*/ A<X extends B> {}
class A<X extends B> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ B<X extends C> {}
class B<X extends C> {}
// ^
// [cfe] Generic type 'B' can't be used without type arguments in the bounds of its own type variables. It is referenced indirectly through 'C'.
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
class /*@compile-error=unspecified*/ C<X extends A<B>> {}
class C<X extends A<B>> {}
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_INSTANTIATED_BOUND
main() {}

View file

@ -6,9 +6,14 @@
import "package:expect/expect.dart";
int returnString1() => 's'; /*@compile-error=unspecified*/
int returnString1() => 's';
// ^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
// OK to return anything from a void function with a "=>" body.
void returnNull() => null;
void returnString2() => 's'; /*@compile-error=unspecified*/
void returnString2() => 's';
main() {
returnString1();