-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
7475c63
commit 3414b51
Showing
7 changed files
with
271 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; }; | ||
} |