From 3414b516755486eea788117125e17d4f7c4e0861 Mon Sep 17 00:00:00 2001 From: Robert Nystrom Date: Tue, 4 Feb 2020 10:37:43 +0000 Subject: [PATCH] Migrate language_2/assign to NNBD. Change-Id: I71947bc5726f168fc036a7fece8a3b6b7bf964f5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134224 Auto-Submit: Bob Nystrom Commit-Queue: Erik Ernst Reviewed-by: Erik Ernst --- .../language/assign/instance_method_test.dart | 23 +++++ tests/language/assign/op_test.dart | 96 +++++++++++++++++++ .../assign/static_type_runtime_test.dart | 28 ++++++ tests/language/assign/static_type_test.dart | 45 +++++++++ .../language/assign/to_type_runtime_test.dart | 28 ++++++ tests/language/assign/to_type_test.dart | 37 +++++++ tests/language/assign/top_method_test.dart | 14 +++ 7 files changed, 271 insertions(+) create mode 100644 tests/language/assign/instance_method_test.dart create mode 100644 tests/language/assign/op_test.dart create mode 100644 tests/language/assign/static_type_runtime_test.dart create mode 100644 tests/language/assign/static_type_test.dart create mode 100644 tests/language/assign/to_type_runtime_test.dart create mode 100644 tests/language/assign/to_type_test.dart create mode 100644 tests/language/assign/top_method_test.dart diff --git a/tests/language/assign/instance_method_test.dart b/tests/language/assign/instance_method_test.dart new file mode 100644 index 0000000000000..0b4fa35836153 --- /dev/null +++ b/tests/language/assign/instance_method_test.dart @@ -0,0 +1,23 @@ +// Copyright (c) 2011, 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. + +import 'package:expect/expect.dart'; + +class A { + A() {} + imethod() { + return 0; + } +} + +main() { + dynamic a = new A(); + + // Illegal, can't change a member method. + Expect.throws(() { + a.imethod = () { + return 1; + }; + }); +} diff --git a/tests/language/assign/op_test.dart b/tests/language/assign/op_test.dart new file mode 100644 index 0000000000000..9ee3eae2f8365 --- /dev/null +++ b/tests/language/assign/op_test.dart @@ -0,0 +1,96 @@ +// Copyright (c) 2011, 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. +// Dart test program for testing assign operators. +// VMOptions=--optimization-counter-threshold=10 --no-background-compilation + +import "package:expect/expect.dart"; + +class AssignOpTest { + AssignOpTest() {} + + static testMain() { + var b = 0; + b += 1; + Expect.equals(1, b); + b *= 5; + Expect.equals(5, b); + b -= 1; + Expect.equals(4, b); + b ~/= 2; + Expect.equals(2, b); + + f = 0; + f += 1; + Expect.equals(1, f); + f *= 5; + Expect.equals(5, f); + f -= 1; + Expect.equals(4, f); + f ~/= 2; + Expect.equals(2, f); + f /= 4; + Expect.equals(.5, f); + + AssignOpTest.f = 0; + AssignOpTest.f += 1; + Expect.equals(1, AssignOpTest.f); + AssignOpTest.f *= 5; + Expect.equals(5, AssignOpTest.f); + AssignOpTest.f -= 1; + Expect.equals(4, AssignOpTest.f); + AssignOpTest.f ~/= 2; + Expect.equals(2, AssignOpTest.f); + AssignOpTest.f /= 4; + Expect.equals(.5, f); + + var o = new AssignOpTest(); + o.instf = 0; + o.instf += 1; + Expect.equals(1, o.instf); + o.instf *= 5; + Expect.equals(5, o.instf); + o.instf -= 1; + Expect.equals(4, o.instf); + o.instf ~/= 2; + Expect.equals(2, o.instf); + o.instf /= 4; + Expect.equals(.5, o.instf); + + var x = 0xFF; + x >>= 3; + Expect.equals(0x1F, x); + x <<= 3; + Expect.equals(0xF8, x); + x |= 0xF00; + Expect.equals(0xFF8, x); + x &= 0xF0; + Expect.equals(0xF0, x); + x ^= 0x11; + Expect.equals(0xE1, x); + + var y = 100; + y += 1 << 3; + Expect.equals(108, y); + y *= 2 + 1; + Expect.equals(324, y); + y -= 3 - 2; + Expect.equals(323, y); + y += 3 * 4; + Expect.equals(335, y); + + var a = [1, 2, 3]; + var ix = 0; + a[ix] |= 12; + Expect.equals(13, a[ix]); + } + + static var f; + var instf; +} + +main() { + for (int i = 0; i < 20; i++) { + AssignOpTest.testMain(); + } +} diff --git a/tests/language/assign/static_type_runtime_test.dart b/tests/language/assign/static_type_runtime_test.dart new file mode 100644 index 0000000000000..2b0c4a4119ca4 --- /dev/null +++ b/tests/language/assign/static_type_runtime_test.dart @@ -0,0 +1,28 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// This test insures that statically initialized variables, fields, and +// parameters report compile-time errors. + + + +class A { + + + + A() { + + } + method( + [ + + g = "String"]) { + return g; + } +} + +main() {} diff --git a/tests/language/assign/static_type_test.dart b/tests/language/assign/static_type_test.dart new file mode 100644 index 0000000000000..d184bf4c1c024 --- /dev/null +++ b/tests/language/assign/static_type_test.dart @@ -0,0 +1,45 @@ +// 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. + +// This test insures that statically initialized variables, fields, and +// parameters report compile-time errors. + +int a = "String"; +// ^^^^^^^^ +// [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT +// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + +class A { + static const int c = "String"; + // ^^^^^^^^ + // [analyzer] CHECKED_MODE_COMPILE_TIME_ERROR.VARIABLE_TYPE_MISMATCH + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + // ^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT + final int d = "String"; + // ^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + int e = "String"; + // ^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + A() { + int f = "String"; + // ^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + } + method( + [ + int + g = "String"]) { + // ^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT + // [cfe] A value of type 'String' can't be assigned to a variable of type 'int'. + return g; + } +} + +main() {} diff --git a/tests/language/assign/to_type_runtime_test.dart b/tests/language/assign/to_type_runtime_test.dart new file mode 100644 index 0000000000000..ecb363e55e470 --- /dev/null +++ b/tests/language/assign/to_type_runtime_test.dart @@ -0,0 +1,28 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// Copyright (c) 2015, 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. + +// Verify that an attempt to assign to a class, enum, typedef, or type +// parameter produces a compile error. + +class C { + f() { + + } +} + +class D {} + +enum E { e0 } + +typedef void F(); + +main() { + new C().f(); + + + +} diff --git a/tests/language/assign/to_type_test.dart b/tests/language/assign/to_type_test.dart new file mode 100644 index 0000000000000..3b09b48a6e1b0 --- /dev/null +++ b/tests/language/assign/to_type_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2015, 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. + +// Verify that an attempt to assign to a class, enum, typedef, or type +// parameter produces a compile error. + +class C { + f() { + T = null; +// ^ +// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_TYPE +// [cfe] Setter not found: 'T'. + } +} + +class D {} + +enum E { e0 } + +typedef void F(); + +main() { + new C().f(); + D = null; +//^ +// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_TYPE +// [cfe] Setter not found: 'D'. + E = null; +//^ +// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_TYPE +// [cfe] Setter not found: 'E'. + F = null; +//^ +// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_TYPE +// [cfe] Setter not found: 'F'. +} diff --git a/tests/language/assign/top_method_test.dart b/tests/language/assign/top_method_test.dart new file mode 100644 index 0000000000000..1b889b915f42b --- /dev/null +++ b/tests/language/assign/top_method_test.dart @@ -0,0 +1,14 @@ +// 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. + +import "package:expect/expect.dart"; + +method() { + return 0; +} + +main() { + // Illegal, can't change a top level method + /*@compile-error=unspecified*/ method = () { return 1; }; +}