Migrate "n" through "p" directory language tests off @compile-error.

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

Change-Id: I6564643302f66c5920b38d2269c160099322560b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296421
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom 2023-04-20 17:56:18 +00:00 committed by Commit Queue
parent 924b9f55ba
commit cd5883fa85
16 changed files with 72 additions and 150 deletions

View file

@ -15,6 +15,9 @@ abstract class Foo {
int foo();
}
/*@compile-error=unspecified*/ class WarnMe extends Mock implements Foo {}
class WarnMe extends Mock implements Foo {}
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER
// [cfe] The non-abstract class 'WarnMe' is missing implementations for these members:
main() {}

View file

@ -8,11 +8,17 @@
import 'package:expect/expect.dart';
class A {
operator ==(other) => 42; /*@compile-error=unspecified*/
operator ==(other) => 42;
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'int' can't be returned from a function with return type 'bool'.
}
class B extends A {
foo() => (super == null) + 4; /*@compile-error=unspecified*/
foo() => (super == null) + 4;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR
// [cfe] The operator '+' isn't defined for the class 'bool'.
}
main() {

View file

@ -22,7 +22,10 @@ main() {
// When the lhs of a logical or fails, it must not assume that all negative is
// checks in it, have failed.
// Here, the `o is! num` check succeeds, but the length test failed.
if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { /*@compile-error=unspecified*/
if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) {
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] The getter 'length' isn't defined for the class 'Object'.
Expect.fail("Type-check failed");
}
}

View file

@ -5,11 +5,14 @@
import "package:expect/expect.dart";
class A {
operator ==(other) => 1; /*@compile-error=unspecified*/
operator <(other) => null; /*@compile-error=unspecified*/
operator <=(other) => 499; /*@compile-error=unspecified*/
operator >(other) => "foo"; /*@compile-error=unspecified*/
operator >=(other) => 42; /*@compile-error=unspecified*/
operator ==(other) => 1;
// ^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'int' can't be returned from a function with return type 'bool'.
operator <(other) => null;
operator <=(other) => 499;
operator >(other) => "foo";
operator >=(other) => 42;
}
// This triggered a bug in Dart2Js: equality operator was always boolified.

View file

@ -1,62 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// 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.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
import "package:expect/expect.dart";
// Test optimized constant string and constant array access.
void testConstantStringAndIndexCodeUnitAt() {
int test(b) {
if (b) return "hest".codeUnitAt(400);
return "hest".codeUnitAt(2);
}
Expect.throws(() => test(true));
for (int i = 0; i < 20; i++) test(false);
Expect.throws(() => test(true));
}
void testConstantArrayAndIndexAt() {
int testPositive(b) {
var a = const [1, 2, 3, 4];
if (b) return a[400];
return a[2];
}
int testNegative(b) {
var a = const [1, 2, 3, 4];
if (b) return a[-1];
return a[2];
}
Expect.throws(() => testPositive(true));
for (int i = 0; i < 20; i++) testPositive(false);
Expect.throws(() => testPositive(true));
Expect.throws(() => testNegative(true));
for (int i = 0; i < 20; i++) testNegative(false);
Expect.throws(() => testNegative(true));
}
foo(a) {
if (a == 1) {
return 2;
}
var aa = const [1, 2];
return aa[2.3]; /*@compile-error=unspecified*/
}
void testNonSmiIndex() {
for (int i = 0; i < 20; i++) {
foo(1);
}
Expect.throws(() => foo(2));
}
main() {
testConstantStringAndIndexCodeUnitAt();
testConstantArrayAndIndexAt();
testNonSmiIndex();
}

View file

@ -10,5 +10,8 @@ int test(int a, [int? b]) {
main() {
// Parameter b passed twice, as positional and named.
test(10, 25, b: 26); /*@compile-error=unspecified*/
test(10, 25, b: 26);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'b'.
}

View file

@ -10,5 +10,8 @@ int test(int a, [int? b]) {
main() {
// 1 positional arg, as expected. Param x does not exist.
test(10, x: 99); /*@compile-error=unspecified*/
test(10, x: 99);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'x'.
}

View file

@ -15,5 +15,8 @@ int test(int a) {
main() {
// 1 positional arg, as expected. Param x does not exist.
test(10, x: 99); /*@compile-error=unspecified*/
test(10, x: 99);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'x'.
}

View file

@ -17,6 +17,9 @@ abstract class Foo {
int foo();
}
/*@compile-error=unspecified*/ class WarnMe extends Mock implements Foo {}
class WarnMe extends Mock implements Foo {}
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER
// [cfe] The non-abstract class 'WarnMe' is missing implementations for these members:
main() {}

View file

@ -10,11 +10,17 @@
import 'package:expect/expect.dart';
class A {
operator ==(other) => 42; /*@compile-error=unspecified*/
operator ==(other) => 42;
// ^^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'.
}
class B extends A {
foo() => (super == null) + 4; /*@compile-error=unspecified*/
foo() => (super == null) + 4;
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_OPERATOR
// [cfe] The operator '+' isn't defined for the class 'bool'.
}
main() {

View file

@ -24,7 +24,10 @@ main() {
// When the lhs of a logical or fails, it must not assume that all negative is
// checks in it, have failed.
// Here, the `o is! num` check succeeds, but the length test failed.
if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) { /*@compile-error=unspecified*/
if ((o is! num && o.length == 4) || (nonInlinedNumTypeCheck(o))) {
// ^^^^^^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_GETTER
// [cfe] The getter 'length' isn't defined for the class 'Object'.
Expect.fail("Type-check failed");
}
}

View file

@ -7,11 +7,14 @@
import "package:expect/expect.dart";
class A {
operator ==(other) => 1; /*@compile-error=unspecified*/
operator <(other) => null; /*@compile-error=unspecified*/
operator <=(other) => 499; /*@compile-error=unspecified*/
operator >(other) => "foo"; /*@compile-error=unspecified*/
operator >=(other) => 42; /*@compile-error=unspecified*/
operator ==(other) => 1;
// ^
// [analyzer] COMPILE_TIME_ERROR.RETURN_OF_INVALID_TYPE
// [cfe] A value of type 'int' can't be assigned to a variable of type 'bool'.
operator <(other) => null;
operator <=(other) => 499;
operator >(other) => "foo";
operator >=(other) => 42;
}
// This triggered a bug in Dart2Js: equality operator was always boolified.

View file

@ -1,64 +0,0 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// 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.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
// @dart = 2.9
import "package:expect/expect.dart";
// Test optimized constant string and constant array access.
int testConstantStringAndIndexCodeUnitAt() {
int test(b) {
if (b) return "hest".codeUnitAt(400);
return "hest".codeUnitAt(2);
}
Expect.throws(() => test(true));
for (int i = 0; i < 20; i++) test(false);
Expect.throws(() => test(true));
}
int testConstantArrayAndIndexAt() {
int testPositive(b) {
var a = const [1, 2, 3, 4];
if (b) return a[400];
return a[2];
}
int testNegative(b) {
var a = const [1, 2, 3, 4];
if (b) return a[-1];
return a[2];
}
Expect.throws(() => testPositive(true));
for (int i = 0; i < 20; i++) testPositive(false);
Expect.throws(() => testPositive(true));
Expect.throws(() => testNegative(true));
for (int i = 0; i < 20; i++) testNegative(false);
Expect.throws(() => testNegative(true));
}
foo(a) {
if (a == 1) {
return 2;
}
var aa = const [1, 2];
return aa[2.3]; /*@compile-error=unspecified*/
}
int testNonSmiIndex() {
for (int i = 0; i < 20; i++) {
foo(1);
}
Expect.throws(() => foo(2));
}
main() {
testConstantStringAndIndexCodeUnitAt();
testConstantArrayAndIndexAt();
testNonSmiIndex();
}

View file

@ -12,5 +12,8 @@ int test(int a, [int b]) {
main() {
// Parameter b passed twice, as positional and named.
test(10, 25, b: 26); /*@compile-error=unspecified*/
test(10, 25, b: 26);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'b'.
}

View file

@ -12,5 +12,8 @@ int test(int a, [int b]) {
main() {
// 1 positional arg, as expected. Param x does not exist.
test(10, x: 99); /*@compile-error=unspecified*/
test(10, x: 99);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'x'.
}

View file

@ -17,5 +17,8 @@ int test(int a) {
main() {
// 1 positional arg, as expected. Param x does not exist.
test(10, x: 99); /*@compile-error=unspecified*/
test(10, x: 99);
// ^
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
// [cfe] No named parameter with the name 'x'.
}