Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d872aea

Browse files
munificentcommit-bot@chromium.org
authored andcommitted
Migrate language_2/typedef to NNBD.
Change-Id: I415eb8b53e7808c9a09cbc725a422f432f084f66 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151924 Auto-Submit: Bob Nystrom <[email protected]> Commit-Queue: Bob Nystrom <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]> Reviewed-by: Srujan Gaddam <[email protected]>
1 parent 5f0a94b commit d872aea

9 files changed

+290
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// TODO(multitest): This was automatically migrated from a multitest and may
2+
// contain strange or dead code.
3+
4+
// Copyright (c) 2016, 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+
// Dart test for a function type test that cannot be eliminated at compile time.
8+
9+
import "package:expect/expect.dart";
10+
11+
typedef int H(
12+
Function
13+
14+
x);
15+
16+
main() {
17+
bool b = true;
18+
Expect.isFalse(b is H);
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
// Dart test for a function type test that cannot be eliminated at compile time.
5+
6+
import "package:expect/expect.dart";
7+
8+
typedef int H(
9+
Function
10+
Function
11+
x);
12+
// ^
13+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
14+
// [cfe] Expected ')' before this.
15+
16+
main() {
17+
bool b = true;
18+
Expect.isFalse(b is H);
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2018, 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+
// Check that typedef type parameters are verified to satisfy their bounds.
6+
7+
typedef F<T extends num> = T Function<U>(T x);
8+
9+
void g(/*@compile-error=unspecified*/ F<String>? f) {}
10+
11+
main() {
12+
g(null);
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2018, 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+
// Check that typedef type parameters are verified to satisfy their bounds.
6+
7+
typedef T F<T extends num>(T x);
8+
9+
void g(/*@compile-error=unspecified*/ F<String>? f) {}
10+
11+
main() {
12+
g(null);
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2018, 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+
// Check that typedef type parameters are verified to satisfy their bounds, even
6+
// if the type parameter in question isn't used by the typedef.
7+
8+
typedef void F<T extends num>();
9+
10+
void g(/*@compile-error=unspecified*/ F<String>? f) {}
11+
12+
main() {
13+
g(null);
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright (c) 2017, 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+
class Bar {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2017, 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+
// This has crashed DDC with Kernel because of a
6+
// "Concurrent modification during iteration" exception.
7+
8+
import 'class_in_other_file_helper.dart';
9+
10+
typedef bool Foo1(bool baz);
11+
typedef bool Foo2(Bar baz);
12+
13+
main() {}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
// Check that cyclic reference of a typedef is a compile-time error.
6+
7+
// To test various cyclic references the definition of the [:typedef A():] is
8+
// split over several lines:
9+
typedef
10+
11+
// Cyclic through return type.
12+
A //# 01: compile-time error
13+
14+
A // The name of the typedef
15+
16+
// Cyclic through type variable bound.
17+
<T extends A> //# 10: compile-time error
18+
19+
// Cyclic through generic type variable bound.
20+
<T extends List<A>> //# 11: compile-time error
21+
22+
(// The left parenthesis of the typedef arguments.
23+
24+
// Cyclic through parameter type.
25+
A a //# 02: compile-time error
26+
27+
// Cyclic through optional parameter type.
28+
[A a] //# 03: compile-time error
29+
30+
// Cyclic through named parameter type.
31+
{A a} //# 04: compile-time error
32+
33+
// Cyclic through generic parameter type.
34+
List<A> a //# 05: compile-time error
35+
36+
// Cyclic through return type of function typed parameter.
37+
A f() //# 06: compile-time error
38+
39+
// Cyclic through parameter type of function typed parameter.
40+
f(A a) //# 07: compile-time error
41+
42+
// Cyclic through another typedef.
43+
B b //# 08: compile-time error
44+
45+
// Cyclic through another more typedefs.
46+
C c //# 09: compile-time error
47+
48+
// Reference through a class is not a cyclic self-reference.
49+
Class c //# 12: ok
50+
51+
// Reference through a class type bound is not a cyclic self-reference.
52+
Class c //# 13: compile-time error
53+
54+
); // The right parenthesis of the typedef arguments.
55+
56+
typedef B(A a);
57+
typedef C(B b);
58+
59+
class Class
60+
<T extends A> //# 13: continued
61+
{
62+
A? a; //# 12: continued
63+
}
64+
65+
void testA(A? a) {}
66+
67+
void main() {
68+
testA(null);
69+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright (c) 2012, 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+
// Test is-test of typedefs with optional and named parameters.
8+
9+
typedef int Func1(int a);
10+
typedef int Func2(int a, [int b]);
11+
typedef int Func3(int a, [int b, int c]);
12+
typedef int Func4([int a, int b, int c]);
13+
typedef int Func5(int a, {int b});
14+
typedef int Func6(int a, {int b, int c});
15+
typedef int Func7({int a, int b, int c});
16+
17+
void main() {
18+
int func1(int i) => -1;
19+
Expect.isTrue(func1 is Func1);
20+
Expect.isFalse(func1 is Func2);
21+
Expect.isFalse(func1 is Func3);
22+
Expect.isFalse(func1 is Func4);
23+
Expect.isFalse(func1 is Func5);
24+
Expect.isFalse(func1 is Func6);
25+
Expect.isFalse(func1 is Func7);
26+
27+
int func2(int i, int j) => -1;
28+
Expect.isFalse(func2 is Func1);
29+
Expect.isFalse(func2 is Func2);
30+
Expect.isFalse(func2 is Func3);
31+
Expect.isFalse(func2 is Func4);
32+
Expect.isFalse(func2 is Func5);
33+
Expect.isFalse(func2 is Func6);
34+
Expect.isFalse(func2 is Func7);
35+
36+
int func3(int i, int j, int k) => -1;
37+
Expect.isFalse(func3 is Func1);
38+
Expect.isFalse(func3 is Func2);
39+
Expect.isFalse(func3 is Func3);
40+
Expect.isFalse(func3 is Func4);
41+
Expect.isFalse(func3 is Func5);
42+
Expect.isFalse(func3 is Func6);
43+
Expect.isFalse(func3 is Func7);
44+
45+
int func4(int i, [int j = -1]) => -1;
46+
Expect.isTrue(func4 is Func1);
47+
Expect.isTrue(func4 is Func2);
48+
Expect.isFalse(func4 is Func3);
49+
Expect.isFalse(func4 is Func4);
50+
Expect.isFalse(func4 is Func5);
51+
Expect.isFalse(func4 is Func6);
52+
Expect.isFalse(func4 is Func7);
53+
54+
int func5(int i, [int j = -1, int k = -1]) => -1;
55+
Expect.isTrue(func5 is Func1);
56+
Expect.isTrue(func5 is Func2);
57+
Expect.isTrue(func5 is Func3);
58+
Expect.isFalse(func5 is Func4);
59+
Expect.isFalse(func5 is Func5);
60+
Expect.isFalse(func5 is Func6);
61+
Expect.isFalse(func5 is Func7);
62+
63+
int func6([int i = -1, int j = -1, int k = -1]) => -1;
64+
Expect.isTrue(func6 is Func1);
65+
Expect.isTrue(func6 is Func2);
66+
Expect.isTrue(func6 is Func3);
67+
Expect.isTrue(func6 is Func4);
68+
Expect.isFalse(func6 is Func5);
69+
Expect.isFalse(func6 is Func6);
70+
Expect.isFalse(func6 is Func7);
71+
72+
int func7(int i, {int j = -1}) => -1;
73+
Expect.isTrue(func7 is Func1);
74+
Expect.isFalse(func7 is Func2);
75+
Expect.isFalse(func7 is Func3);
76+
Expect.isFalse(func7 is Func4);
77+
Expect.isFalse(func7 is Func5);
78+
Expect.isFalse(func7 is Func6);
79+
Expect.isFalse(func7 is Func7);
80+
81+
int func8(int i, {int b = -1}) => -1;
82+
Expect.isTrue(func8 is Func1);
83+
Expect.isFalse(func8 is Func2);
84+
Expect.isFalse(func8 is Func3);
85+
Expect.isFalse(func8 is Func4);
86+
Expect.isTrue(func8 is Func5);
87+
Expect.isFalse(func8 is Func6);
88+
Expect.isFalse(func8 is Func7);
89+
90+
int func9(int i, {int b = -1, int c = -1}) => -1;
91+
Expect.isTrue(func9 is Func1);
92+
Expect.isFalse(func9 is Func2);
93+
Expect.isFalse(func9 is Func3);
94+
Expect.isFalse(func9 is Func4);
95+
Expect.isTrue(func9 is Func5);
96+
Expect.isTrue(func9 is Func6);
97+
Expect.isFalse(func9 is Func7);
98+
99+
int func10(int i, {int c = -1, int b = -1}) => -1;
100+
Expect.isTrue(func10 is Func1);
101+
Expect.isFalse(func10 is Func2);
102+
Expect.isFalse(func10 is Func3);
103+
Expect.isFalse(func10 is Func4);
104+
Expect.isTrue(func10 is Func5);
105+
Expect.isTrue(func10 is Func6);
106+
Expect.isFalse(func10 is Func7);
107+
108+
int func11({int a = -1, int b = -1, int c = -1}) => -1;
109+
Expect.isFalse(func11 is Func1);
110+
Expect.isFalse(func11 is Func2);
111+
Expect.isFalse(func11 is Func3);
112+
Expect.isFalse(func11 is Func4);
113+
Expect.isFalse(func11 is Func5);
114+
Expect.isFalse(func11 is Func6);
115+
Expect.isTrue(func11 is Func7);
116+
117+
int func12({int c = -1, int a = -1, int b = -1}) => -1;
118+
Expect.isFalse(func12 is Func1);
119+
Expect.isFalse(func12 is Func2);
120+
Expect.isFalse(func12 is Func3);
121+
Expect.isFalse(func12 is Func4);
122+
Expect.isFalse(func12 is Func5);
123+
Expect.isFalse(func12 is Func6);
124+
Expect.isTrue(func12 is Func7);
125+
}

0 commit comments

Comments
 (0)