Skip to content

Commit bd8f87d

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[wildcard-variables] Test non-binding behaviour with top-level declarations.
Added a little section for late wildcard variables too. This CL tests mixing top-level wildcard declarations with local wildcard declarations and the non-shadowing, non-binding behaviour. Bug: #55652 Change-Id: I72e7cfb1b2d80a3934af355579c36252881cf3fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367241 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent ffbbdb5 commit bd8f87d

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

tests/language/wildcard_variables/multiple/local_declaration_local_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ void main() {
1616

1717
int _;
1818
final _;
19+
20+
late int _;
21+
late int _ = 2;
22+
23+
late final int _;
24+
late final int _ = 2;
1925
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2024, 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 the interactions between a wildcard class members, which are binding,
6+
// with local non-binding wildcard variables.
7+
8+
// SharedOptions=--enable-experiment=wildcard-variables
9+
10+
import 'package:expect/expect.dart';
11+
12+
void main() {
13+
InstanceMember().member();
14+
StaticMember().member();
15+
}
16+
17+
class InstanceMember {
18+
var _ = 2;
19+
20+
void member<_, _>() {
21+
int _ = _;
22+
int _ = 2;
23+
const _ = 2;
24+
int _() => 2;
25+
_ = 3;
26+
Expect.equals(3, _);
27+
28+
int _() => 2;
29+
30+
int foo<_>([int _ = 5]) => _;
31+
Expect.equals(3, foo());
32+
}
33+
}
34+
35+
class StaticMember {
36+
static const _ = 2;
37+
38+
void member<_, _>() {
39+
int _ = _;
40+
int _ = 2;
41+
const _ = 2;
42+
const _ = _ - 1;
43+
int _() => 2;
44+
_ = 3;
45+
Expect.equals(3, _);
46+
47+
int foo<_>([int _ = _ + 1]) => _;
48+
Expect.equals(3, foo());
49+
}
50+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2024, 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 the interactions between a wildcard top-level function, which is
6+
// binding, with local non-binding wildcard variables.
7+
8+
// SharedOptions=--enable-experiment=wildcard-variables
9+
10+
import 'package:expect/expect.dart';
11+
12+
int _(int _) => 2;
13+
14+
void main() {
15+
int _ = 1;
16+
const _ = 1;
17+
int _() => 1;
18+
Expect.equals(2, _(1));
19+
}
20+
21+
class Clas<_> {
22+
void member<_>() {
23+
int _ = 1;
24+
const _ = 1;
25+
int _() => 1;
26+
Expect.equals(2, _(1));
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2024, 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 the interactions between a wildcard typedef, which is binding, with
6+
// local non-binding wildcard variables.
7+
8+
// SharedOptions=--enable-experiment=wildcard-variables
9+
10+
import 'package:expect/expect.dart';
11+
12+
typedef _ = Type;
13+
14+
_ function<_ extends _>([_ _ = _]) => _;
15+
16+
void main<_ extends _>() {
17+
_ _ = _;
18+
final _ _ = _;
19+
const _ _ = _;
20+
_ foo<_ extends _>([_ _ = int]) => _;
21+
_ bar<_ extends _>([_ _ = _]) => int;
22+
Expect.type<Type>(foo());
23+
Expect.type<int>(bar());
24+
}
25+
26+
class CConst {
27+
static const _ = 42;
28+
void member<_>() {
29+
var _ = _;
30+
final _ = _;
31+
const _ = _;
32+
int _() => 1;
33+
int foo<_>([String _ = "$_"]) => _;
34+
_ = foo();
35+
}
36+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2024, 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 the interactions between a wildcard top-level variable, which is
6+
// binding, with local non-binding wildcard variables.
7+
8+
// SharedOptions=--enable-experiment=wildcard-variables
9+
10+
import 'package:expect/expect.dart';
11+
12+
var _ = 2;
13+
14+
void main() {
15+
Clas().member();
16+
17+
int _ = _;
18+
int _ = 2;
19+
_ = 3;
20+
Expect.equals(3, _);
21+
}
22+
23+
class Clas<_> {
24+
void member<_>() {
25+
int _ = _;
26+
int _ = 2;
27+
Expect.equals(2, _);
28+
_ = 4;
29+
Expect.equals(4, _);
30+
31+
int foo<_>([int _ = 5]) => _;
32+
Expect.equals(4, foo());
33+
}
34+
}

0 commit comments

Comments
 (0)