Skip to content

Commit 7c10084

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Migrate language_2/static to NNBD.
Change-Id: I0cdd3bd28c7f9135811b3d66237e76fa8a0cc71a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151100 Auto-Submit: Bob Nystrom <[email protected]> Commit-Queue: Erik Ernst <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 755686e commit 7c10084

30 files changed

+879
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Test mismatch in argument counts.
6+
class Niesen {
7+
static int goodCall(int a, int b, int c) {
8+
return a + b;
9+
}
10+
}
11+
12+
main() {
13+
Niesen.goodCall(1, 2, 3);
14+
15+
Niesen.goodCall(1, 2, 3, 4);
16+
// ^^^^^^^^^^^^
17+
// [analyzer] COMPILE_TIME_ERROR.EXTRA_POSITIONAL_ARGUMENTS
18+
// [cfe] Too many positional arguments: 3 allowed, but 4 found.
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
var foo = main;
8+
9+
main() {
10+
Expect.equals(main, main);
11+
Expect.identical(main, main);
12+
Expect.equals(main.hashCode, main.hashCode);
13+
14+
Expect.equals(main, foo);
15+
Expect.identical(main, foo);
16+
Expect.equals(main.hashCode, foo.hashCode);
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Dart test for testing redefinition of reserved names as static const fields.
6+
// Issue https://github.com/dart-archive/dev_compiler/issues/587
7+
8+
import "package:expect/expect.dart";
9+
10+
class Field {
11+
static const name = 'Foo';
12+
}
13+
14+
class StaticConstFieldReservedNameTest {
15+
static testMain() {
16+
Expect.equals('Foo', Field.name);
17+
}
18+
}
19+
20+
class Foo {
21+
int get foo => 42;
22+
static final baz = new Foo();
23+
}
24+
25+
class Bar extends Foo {
26+
get foo => 123;
27+
Bar.baz();
28+
}
29+
30+
void main() {
31+
StaticConstFieldReservedNameTest.testMain();
32+
33+
// Regression test for https://github.com/dart-lang/sdk/issues/33621
34+
Expect.equals(Bar.baz().foo, 123);
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
// Dart test program for testing static const fields.
5+
6+
import "package:expect/expect.dart";
7+
8+
abstract class Spain {
9+
static const AG = "Antoni Gaudi";
10+
static const SD = "Salvador Dali";
11+
}
12+
13+
abstract class Switzerland {
14+
static const AG = "Alberto Giacometti";
15+
static const LC = "Le Corbusier";
16+
}
17+
18+
class A implements Switzerland {
19+
const A() : n = 5;
20+
final n;
21+
static const a = const A();
22+
static const b = 3 + 5;
23+
static const c = A.b + 7;
24+
static const d = const A();
25+
static const s1 = "hula";
26+
static const s2 = "hula";
27+
static const s3 = "hop";
28+
static const d1 = 1.1;
29+
static const d2 = 0.55 + 0.55;
30+
static const artist2 = Switzerland.AG;
31+
static const architect1 = Spain.AG;
32+
static const array1 = const <int>[1, 2];
33+
static const map1 = const {
34+
"Monday": 1,
35+
"Tuesday": 2,
36+
};
37+
}
38+
39+
class StaticFinalFieldTest {
40+
static testMain() {
41+
Expect.equals(15, A.c);
42+
Expect.equals(8, A.b);
43+
Expect.equals(5, A.a.n);
44+
Expect.equals(true, identical(8, A.b));
45+
Expect.equals(true, identical(A.a, A.d));
46+
Expect.equals(true, identical(A.s1, A.s2));
47+
Expect.equals(false, identical(A.s1, A.s3));
48+
Expect.equals(false, identical(A.s1, A.b));
49+
Expect.equals(true, identical(A.d1, A.d2));
50+
Expect.equals(true, Spain.SD == "Salvador Dali");
51+
Expect.equals(true, A.artist2 == "Alberto Giacometti");
52+
Expect.equals(true, A.architect1 == "Antoni Gaudi");
53+
Expect.equals(2, A.map1["Tuesday"]);
54+
}
55+
}
56+
57+
main() {
58+
StaticFinalFieldTest.testMain();
59+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// TODO(multitest): This was automatically migrated from a multitest and may
2+
// contain strange or dead code.
3+
4+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
5+
// for details. All rights reserved. Use of this source code is governed by a
6+
// BSD-style license that can be found in the LICENSE file.
7+
// Test that a static field cannot be read as an instance field.
8+
9+
class Foo {
10+
Foo() {}
11+
static var x;
12+
}
13+
14+
class StaticField1Test {
15+
static testMain() {
16+
if (false) {
17+
var foo = new Foo();
18+
19+
}
20+
}
21+
}
22+
23+
main() {
24+
StaticField1Test.testMain();
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
// Test that a static field cannot be read as an instance field.
5+
6+
class Foo {
7+
Foo() {}
8+
static var x;
9+
}
10+
11+
class StaticField1Test {
12+
static testMain() {
13+
if (false) {
14+
var foo = new Foo();
15+
var x = foo.x;
16+
// ^
17+
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
18+
// [cfe] The getter 'x' isn't defined for the class 'Foo'.
19+
}
20+
}
21+
}
22+
23+
main() {
24+
StaticField1Test.testMain();
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// TODO(multitest): This was automatically migrated from a multitest and may
2+
// contain strange or dead code.
3+
4+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
5+
// for details. All rights reserved. Use of this source code is governed by a
6+
// BSD-style license that can be found in the LICENSE file.
7+
// Test that a static method cannot be read as an instance field.
8+
9+
class Foo {
10+
Foo() {}
11+
static void m() {}
12+
}
13+
14+
class StaticField1aTest {
15+
static testMain() {
16+
if (false) {
17+
var foo = new Foo();
18+
19+
}
20+
}
21+
}
22+
23+
main() {
24+
StaticField1aTest.testMain();
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
// Test that a static method cannot be read as an instance field.
5+
6+
class Foo {
7+
Foo() {}
8+
static void m() {}
9+
}
10+
11+
class StaticField1aTest {
12+
static testMain() {
13+
if (false) {
14+
var foo = new Foo();
15+
var m = foo.m;
16+
// ^
17+
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
18+
// [cfe] The getter 'm' isn't defined for the class 'Foo'.
19+
}
20+
}
21+
}
22+
23+
main() {
24+
StaticField1aTest.testMain();
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// TODO(multitest): This was automatically migrated from a multitest and may
2+
// contain strange or dead code.
3+
4+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
5+
// for details. All rights reserved. Use of this source code is governed by a
6+
// BSD-style license that can be found in the LICENSE file.
7+
// Test that an instance field cannot be read as a static field.
8+
9+
class Foo {
10+
Foo() {}
11+
var x;
12+
void m() {}
13+
}
14+
15+
main() {
16+
if (false) {
17+
18+
19+
20+
21+
}
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
// Test that an instance field cannot be read as a static field.
5+
6+
class Foo {
7+
Foo() {}
8+
var x;
9+
void m() {}
10+
}
11+
12+
main() {
13+
if (false) {
14+
var x = Foo.x;
15+
// ^
16+
// [analyzer] STATIC_WARNING.STATIC_ACCESS_TO_INSTANCE_MEMBER
17+
// [cfe] Getter not found: 'x'.
18+
var m = Foo.m;
19+
// ^
20+
// [analyzer] STATIC_WARNING.STATIC_ACCESS_TO_INSTANCE_MEMBER
21+
// [cfe] Getter not found: 'm'.
22+
Foo.m = 1;
23+
// ^
24+
// [analyzer] STATIC_TYPE_WARNING.UNDEFINED_SETTER
25+
// [cfe] Setter not found: 'm'.
26+
Foo.x = 1;
27+
// ^
28+
// [analyzer] STATIC_WARNING.STATIC_ACCESS_TO_INSTANCE_MEMBER
29+
// [cfe] Setter not found: 'x'.
30+
}
31+
}

0 commit comments

Comments
 (0)