Migrate corelib and lib 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: I42d3712f2f75f66e7ecae19f740de16f6025b41d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296120
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
This commit is contained in:
Robert Nystrom 2023-04-20 19:19:01 +00:00 committed by Commit Queue
parent 4d8fa9729e
commit 0eb13c95ac
12 changed files with 161 additions and 46 deletions

View file

@ -16,20 +16,38 @@ class CoreStaticTypesTest {
static testStringOperators() {
var q = "abcdef";
/*@compile-error=unspecified*/ q['hello'];
/*@compile-error=unspecified*/ q[0] = 'x';
q['hello'];
//^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
q[0] = 'x';
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR
// [cfe] The operator '[]=' isn't defined for the class 'String'.
}
static testStringMethods() {
var s = "abcdef";
/*@compile-error=unspecified*/ s.startsWith(1);
/*@compile-error=unspecified*/ s.endsWith(1);
s.startsWith(1);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'Pattern'.
s.endsWith(1);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'String'.
}
static testListOperators() {
var a = [1, 2, 3, 4];
/*@compile-error=unspecified*/ a['0'];
/*@compile-error=unspecified*/ a['0'] = 99;
a['0'];
//^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
a['0'] = 99;
//^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
}
}

View file

@ -6,5 +6,8 @@
import "package:expect/expect.dart";
void main() {
String s4 = new String.fromCharCodes([/*@compile-error=unspecified*/ 0.0]);
String s4 = new String.fromCharCodes([0.0]);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'double' can't be assigned to a variable of type 'int'.
}

View file

@ -6,21 +6,40 @@ import "package:expect/expect.dart";
void main() {
// Test object startIndex
"hello".replaceFirst("h", "X", new Object()); /*@compile-error=unspecified*/
"hello".replaceFirst("h", "X", new Object());
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// ^
// [cfe] The argument type 'Object' can't be assigned to the parameter type 'int'.
// Test object startIndex
"hello".replaceFirstMapped(
"h", (_) => "X", new Object()); /*@compile-error=unspecified*/
"hello".replaceFirstMapped("h", (_) => "X", new Object());
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// ^
// [cfe] The argument type 'Object' can't be assigned to the parameter type 'int'.
"foo-bar".replaceFirstMapped("bar", (v) {
return 42;
}); /*@compile-error=unspecified*/
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE_FROM_CLOSURE
// [cfe] A value of type 'int' can't be returned from a function with return type 'String'.
});
"hello".replaceRange(0, 0, 42); /*@compile-error=unspecified*/
"hello".replaceRange(0, 0, ["x"]); /*@compile-error=unspecified*/
"hello".replaceRange(0, 0, 42);
// ^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'String'.
"hello".replaceRange(0, 0, ["x"]);
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'List<String>' can't be assigned to the parameter type 'String'.
}
// Fails to return a String on toString, throws if converted by "$naughty".
class Naughty {
toString() => this; /*@compile-error=unspecified*/
toString() => this;
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'Naughty' can't be returned from a function with return type 'String'.
}

View file

@ -10,5 +10,8 @@ void main() {
void testIllegalArgument() {
String a = "Hello";
var c = a[2.2]; /*@compile-error=unspecified*/
var c = a[2.2];
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'double' can't be assigned to a variable of type 'int'.
}

View file

@ -18,20 +18,38 @@ class CoreStaticTypesTest {
static testStringOperators() {
var q = "abcdef";
/*@compile-error=unspecified*/ q['hello'];
/*@compile-error=unspecified*/ q[0] = 'x';
q['hello'];
//^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
q[0] = 'x';
// ^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR
// [cfe] The operator '[]=' isn't defined for the class 'String'.
}
static testStringMethods() {
var s = "abcdef";
/*@compile-error=unspecified*/ s.startsWith(1);
/*@compile-error=unspecified*/ s.endsWith(1);
s.startsWith(1);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'Pattern'.
s.endsWith(1);
// ^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'String'.
}
static testListOperators() {
var a = [1, 2, 3, 4];
/*@compile-error=unspecified*/ a['0'];
/*@compile-error=unspecified*/ a['0'] = 99;
a['0'];
//^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
a['0'] = 99;
//^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
}
}

View file

@ -8,5 +8,8 @@
import "package:expect/expect.dart";
void main() {
String s4 = new String.fromCharCodes([/*@compile-error=unspecified*/ 0.0]);
String s4 = new String.fromCharCodes([0.0]);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'double' can't be assigned to a variable of type 'int'.
}

View file

@ -8,21 +8,40 @@ import "package:expect/expect.dart";
void main() {
// Test object startIndex
"hello".replaceFirst("h", "X", new Object()); /*@compile-error=unspecified*/
"hello".replaceFirst("h", "X", new Object());
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_NEW_EXPR
// ^
// [cfe] The constructor returns type 'Object' that isn't of expected type 'int'.
// Test object startIndex
"hello".replaceFirstMapped(
"h", (_) => "X", new Object()); /*@compile-error=unspecified*/
"hello".replaceFirstMapped("h", (_) => "X", new Object());
// ^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_NEW_EXPR
// ^
// [cfe] The constructor returns type 'Object' that isn't of expected type 'int'.
"foo-bar".replaceFirstMapped("bar", (v) {
return 42;
}); /*@compile-error=unspecified*/
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE_FROM_CLOSURE
// [cfe] A value of type 'int' can't be assigned to a variable of type 'String'.
});
"hello".replaceRange(0, 0, 42); /*@compile-error=unspecified*/
"hello".replaceRange(0, 0, ["x"]); /*@compile-error=unspecified*/
"hello".replaceRange(0, 0, 42);
// ^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'int' can't be assigned to the parameter type 'String'.
"hello".replaceRange(0, 0, ["x"]);
// ^^^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'List<String>' can't be assigned to the parameter type 'String'.
}
// Fails to return a String on toString, throws if converted by "$naughty".
class Naughty {
toString() => this; /*@compile-error=unspecified*/
toString() => this;
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'Naughty' can't be assigned to a variable of type 'String'.
}

View file

@ -12,5 +12,8 @@ void main() {
void testIllegalArgument() {
String a = "Hello";
var c = a[2.2]; /*@compile-error=unspecified*/
var c = a[2.2];
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] A value of type 'double' can't be assigned to a variable of type 'int'.
}

View file

@ -9,11 +9,23 @@
import 'dart:async';
import 'package:expect/expect.dart';
class A
extends FutureOr<String> /*@compile-error=unspecified*/
extends Object with FutureOr<bool> /*@compile-error=unspecified*/
implements FutureOr<int> /*@compile-error=unspecified*/
{}
class A extends FutureOr<String> {}
// ^
// [cfe] The superclass, 'FutureOr', has no unnamed constructor that takes no arguments.
// ^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
main() {
}
class B with FutureOr<bool> {}
// ^
// [cfe] Can't use 'FutureOr' as a mixin because it has constructors.
// ^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
// [cfe] The class 'FutureOr' can't be used as a mixin because it isn't a mixin class nor a mixin.
class C implements FutureOr<int> {}
// ^
// [cfe] The type 'FutureOr' can't be used in an 'implements' clause.
// ^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
main() {}

View file

@ -9,5 +9,8 @@ import 'dart:typed_data';
main() {
var str = "foo";
/*@compile-error=unspecified*/ new Float32x4(str, 2.0, 3.0, 4.0);
new Float32x4(str, 2.0, 3.0, 4.0);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'String' can't be assigned to the parameter type 'double'.
}

View file

@ -11,11 +11,22 @@
import 'dart:async';
import 'package:expect/expect.dart';
class A
extends FutureOr<String> /*@compile-error=unspecified*/
extends Object with FutureOr<bool> /*@compile-error=unspecified*/
implements FutureOr<int> /*@compile-error=unspecified*/
{}
class A extends FutureOr<String> {}
// ^
// [cfe] The superclass, 'FutureOr', has no unnamed constructor that takes no arguments.
// ^^^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
main() {
}
class B with FutureOr<bool> {}
// ^
// [cfe] Can't use 'FutureOr' as a mixin because it has constructors.
// ^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
class C implements FutureOr<int> {}
// ^
// [cfe] The type 'FutureOr' can't be used in an 'implements' clause.
// ^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.SUBTYPE_OF_DISALLOWED_TYPE
main() {}

View file

@ -11,5 +11,8 @@ import 'dart:typed_data';
main() {
var str = "foo";
/*@compile-error=unspecified*/ new Float32x4(str, 2.0, 3.0, 4.0);
new Float32x4(str, 2.0, 3.0, 4.0);
// ^^^
// [analyzer] COMPILE_TIME_ERROR.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'String' can't be assigned to the parameter type 'double'.
}