Skip to content

Commit

Permalink
Remove unnecessary leftover @dart=2.19 from tests.
Browse files Browse the repository at this point in the history
Change-Id: I6d5e15ff2d432202618fbc490969a65a9181816d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396281
Reviewed-by: Nicholas Shahan <[email protected]>
Commit-Queue: Lasse Nielsen <[email protected]>
  • Loading branch information
lrhn authored and Commit Queue committed Nov 28, 2024
1 parent dbc9c86 commit 5430e68
Show file tree
Hide file tree
Showing 215 changed files with 4,647 additions and 1,879 deletions.
14 changes: 13 additions & 1 deletion pkg/expect/lib/static_type_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Object? context<T>(T x) => x;
T contextType<T>(Object? result) => result as T;

extension StaticType<T> on T {
/// Check the static type.
/// Check the static type against another type wrt. sub- and supertype.
///
/// Use as follows (assuming `e` has static type `num`):
/// ```dart
Expand Down Expand Up @@ -45,6 +45,18 @@ extension StaticType<T> on T {
callback<T>();
return this;
}

/// The static type as a `Type` object.
///
/// Can be used for doing "same type" equality checks, like
/// ```dart
/// Expect(typeOf<int Function(int)>(), value.functionName.staticType);
/// ```
/// The [Type.operator==] distinguishes some types that are equivalent
/// wrt. super- and sub-typing, like `dynamic` and `Object?`.
/// It also performs normalization, so `typeOf<FutureOr<Object>> == Object`,
/// even if they differ as static types.
Type get staticType => T;
}

/// Invokes [callback] with the static type of [value].
Expand Down
3 changes: 2 additions & 1 deletion pkg/test_runner/lib/src/test_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ abstract class _TestFileBase {

/// The parsed error expectation markers in this test, if it is a static
/// error test.
///
/// If empty, the test is not a static error test.
final List<StaticError> expectedErrors;

/// The name of the multitest section this file corresponds to if it was
Expand Down Expand Up @@ -358,7 +360,6 @@ class TestFile extends _TestFileBase {
result
.addAll(_parseExpectations(uriString, alreadyParsed: alreadyParsed));
}

return result;
}

Expand Down
78 changes: 66 additions & 12 deletions tests/language/async/switch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ foo1(int a) async {
case 2:
k += a;
return k + 2;
default: k = 2; //# withDefault: ok
}
return k;
}
Expand All @@ -34,7 +33,6 @@ foo2(Future<int> a) async {
case 2:
k += await a;
return k + 2;
default: k = 2; //# withDefault: ok
}
return k;
}
Expand All @@ -48,7 +46,6 @@ foo3(int a) async {
case 2:
k += a;
return k + 2;
default: k = 2; //# withDefault: ok
}
return k;
}
Expand All @@ -62,7 +59,64 @@ foo4(value) async {
case 2:
k += 2;
return 2 + k;
default: k = 2; //# withDefault: ok
}
return k;
}

foo1WithDefault(int a) async {
int k = 0;
switch (a) {
case 1:
await 3;
k += 1;
break;
case 2:
k += a;
return k + 2;
default: k = 2;
}
return k;
}

foo2WithDefault(Future<int> a) async {
int k = 0;
switch (await a) {
case 1:
await 3;
k += 1;
break;
case 2:
k += await a;
return k + 2;
default: k = 2;
}
return k;
}

foo3WithDefault(int a) async {
int k = 0;
switch (a) {
case 1:
k += 1;
break;
case 2:
k += a;
return k + 2;
default: k = 2;
}
return k;
}

foo4WithDefault(value) async {
int k = 0;
switch (await value) {
case 1:
k += 1;
break;
case 2:
k += 2;
return 2 + k;
default: k = 2;
}
return k;
}
Expand All @@ -72,20 +126,20 @@ Future<int> futureOf(int a) async => await a;
Future test() async {
Expect.equals(1, await foo1(1));
Expect.equals(4, await foo1(2));
Expect.equals(2, await foo1(3)); //# withDefault: ok
Expect.equals(0, await foo1(3)); //# none: ok
Expect.equals(2, await foo1WithDefault(3));
Expect.equals(0, await foo1(3));
Expect.equals(1, await foo2(futureOf(1)));
Expect.equals(4, await foo2(futureOf(2)));
Expect.equals(2, await foo2(futureOf(3))); //# withDefault: ok
Expect.equals(0, await foo2(futureOf(3))); //# none: ok
Expect.equals(2, await foo2WithDefault(futureOf(3)));
Expect.equals(0, await foo2(futureOf(3)));
Expect.equals(1, await foo3(1));
Expect.equals(4, await foo3(2));
Expect.equals(2, await foo3(3)); //# withDefault: ok
Expect.equals(0, await foo3(3)); //# none: ok
Expect.equals(2, await foo3WithDefault(3));
Expect.equals(0, await foo3(3));
Expect.equals(1, await foo4(futureOf(1)));
Expect.equals(4, await foo4(futureOf(2)));
Expect.equals(2, await foo4(futureOf(3))); //# withDefault: ok
Expect.equals(0, await foo4(futureOf(3))); //# none: ok
Expect.equals(2, await foo4WithDefault(futureOf(3)));
Expect.equals(0, await foo4(futureOf(3)));
}

void main() {
Expand Down
39 changes: 39 additions & 0 deletions tests/language/call/method_as_cast_legacy_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2018, 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";

class B {}

class C {
B call(B b) => b;
}

class D implements Function {
B call(B b) => b;
}

typedef B BToB(B x);

typedef Object NullToObject(Null x);

main() {
// The presence of a `.call` method does not cause class `C` to become a
// subtype of any function type.
C c = new C();
Expect.throwsTypeError(() => c as BToB); //# 01: ok
Expect.throwsTypeError(() => c as NullToObject); //# 02: ok
Expect.throwsTypeError(() => c as Function); //# 03: ok

// The same goes for class `D`: `implements Function` is ignored in Dart 2.
D d = new D();
Expect.throwsTypeError(() => d as BToB); //# 04: ok
Expect.throwsTypeError(() => d as NullToObject); //# 05: ok
Expect.throwsTypeError(() => d as Function); //# 06: ok
}
5 changes: 1 addition & 4 deletions tests/language/call/method_as_cast_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";
Expand All @@ -15,7 +12,7 @@ class C {
B call(B b) => b;
}

class D implements Function {
class D {
B call(B b) => b;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2018, 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";

class C1 {
int call(int i) => 2 * i;
}

class C2 implements Function {
int call(int i) => 2 * i;
}

class D {
C1 c1 = new C1();
dynamic d1 = new C1();
C2 c2 = new C2();
dynamic d2 = new C2();

void test() {
// Implicitly invokes c1.call(1)
Expect.equals(c1(1), 2); //# 01: ok
// Implicitly invokes d1.call(1)
Expect.equals(d1(1), 2); //# 02: ok
// Implicitly invokes c2.call(1)
Expect.equals(c2(1), 2); //# 03: ok
// Implicitly invokes d2.call(1)
Expect.equals(d2(1), 2); //# 04: ok
}
}

main() {
new D().test();
// Implicitly invokes D.c1.call(1)
Expect.equals(new D().c1(1), 2); //# 05: ok
// Implicitly invokes D.d1.call(1)
Expect.equals(new D().d1(1), 2); //# 06: ok
// Implicitly invokes D.c2.call(1)
Expect.equals(new D().c2(1), 2); //# 07: ok
// Implicitly invokes D.d2.call(1)
Expect.equals(new D().d2(1), 2); //# 08: ok
D d = new D();
// Implicitly invokes d.c1.call(1)
Expect.equals(d.c1(1), 2); //# 09: ok
// Implicitly invokes d.d1.call(1)
Expect.equals(d.d1(1), 2); //# 10: ok
// Implicitly invokes d.c2.call(1)
Expect.equals(d.c2(1), 2); //# 11: ok
// Implicitly invokes d.d2.call(1)
Expect.equals(d.d2(1), 2); //# 12: ok
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";
Expand All @@ -13,7 +10,7 @@ class C1 {
int call(int i) => 2 * i;
}

class C2 implements Function {
class C2 {
int call(int i) => 2 * i;
}

Expand Down
44 changes: 44 additions & 0 deletions tests/language/call/method_implicit_invoke_local_legacy_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2018, 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";

class C1 {
int call(int i) => 2 * i;
}

class C2 implements Function {
int call(int i) => 2 * i;
}

main() {
C1 c1 = new C1();
// Implicitly invokes c1.call(1)
Expect.equals(c1(1), 2);
dynamic d1 = c1;
// Implicitly invokes d1.call(1)
Expect.equals(d1(1), 2);
C2 c2 = new C2();
// Implicitly invokes c2.call(1)
Expect.equals(c2(1), 2);
dynamic d2 = c2;
// Implicitly invokes d2.call(1)
Expect.equals(d2(1), 2);
// Cannot invoke with the wrong signature.
c2();
// ^
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
//^^
// [cfe] Too few positional arguments: 1 required, 0 given.
c2(3, 4);
// ^
// [analyzer] COMPILE_TIME_ERROR.EXTRA_POSITIONAL_ARGUMENTS
//^^^^^^
// [cfe] Too many positional arguments: 1 allowed, but 2 found.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.

// Copyright (c) 2018, 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.

// Implements Function which is not allowed in Dart 3.
// @dart=2.19

// Dart test program to test arithmetic operations.

import "package:expect/expect.dart";

class C1 {
int call(int i) => 2 * i;
}

class C2 implements Function {
int call(int i) => 2 * i;
}

main() {
C1 c1 = new C1();
// Implicitly invokes c1.call(1)
Expect.equals(c1(1), 2);
dynamic d1 = c1;
// Implicitly invokes d1.call(1)

C2 c2 = new C2();
// Implicitly invokes c2.call(1)

dynamic d2 = c2;
// Implicitly invokes d2.call(1)

// Cannot invoke with the wrong signature.


}
Loading

0 comments on commit 5430e68

Please sign in to comment.