mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:29:48 +00:00
Migrate language_2/assign to NNBD.
Change-Id: I71947bc5726f168fc036a7fece8a3b6b7bf964f5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134224 Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
7475c637c3
commit
3414b51675
23
tests/language/assign/instance_method_test.dart
Normal file
23
tests/language/assign/instance_method_test.dart
Normal file
|
@ -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;
|
||||
};
|
||||
});
|
||||
}
|
96
tests/language/assign/op_test.dart
Normal file
96
tests/language/assign/op_test.dart
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
28
tests/language/assign/static_type_runtime_test.dart
Normal file
28
tests/language/assign/static_type_runtime_test.dart
Normal file
|
@ -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() {}
|
45
tests/language/assign/static_type_test.dart
Normal file
45
tests/language/assign/static_type_test.dart
Normal file
|
@ -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() {}
|
28
tests/language/assign/to_type_runtime_test.dart
Normal file
28
tests/language/assign/to_type_runtime_test.dart
Normal file
|
@ -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<T> {
|
||||
f() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class D {}
|
||||
|
||||
enum E { e0 }
|
||||
|
||||
typedef void F();
|
||||
|
||||
main() {
|
||||
new C<D>().f();
|
||||
|
||||
|
||||
|
||||
}
|
37
tests/language/assign/to_type_test.dart
Normal file
37
tests/language/assign/to_type_test.dart
Normal file
|
@ -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<T> {
|
||||
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<D>().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'.
|
||||
}
|
14
tests/language/assign/top_method_test.dart
Normal file
14
tests/language/assign/top_method_test.dart
Normal file
|
@ -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; };
|
||||
}
|
Loading…
Reference in a new issue