Skip to content

Commit 54b6fd1

Browse files
authored
#3057. Add pattern-based definite assignment tests (#3102)
1 parent 49b3176 commit 54b6fd1

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

TypeSystem/flow-analysis/definite_assignment_A01_t01.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion assigned is a boolean value indicating whether the variable has
6-
/// definitely been assigned at the given point in the source code. When assigned
7-
/// is true, we say that the variable is definitely assigned at that point.
5+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
89
///
910
/// @description Checks definite assignment via assignment
1011
/// @author [email protected]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2025, 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+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
9+
///
10+
/// @description Checks definite assignment via record pattern assignment.
11+
/// @author [email protected]
12+
13+
main() {
14+
int i, j;
15+
16+
(i,) = (42,);
17+
i; // Definitely assigned
18+
(x: j) = (x: 42);
19+
j;
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2025, 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+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
9+
///
10+
/// @description Checks definite assignment via list pattern assignment.
11+
/// @author [email protected]
12+
13+
main() {
14+
int n;
15+
16+
[n] = [42];
17+
n; // Definitely assigned
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2025, 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+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
9+
///
10+
/// @description Checks definite assignment via map pattern assignment.
11+
/// @author [email protected]
12+
13+
main() {
14+
int n;
15+
16+
{"key": n} = {"key": 42};
17+
n; // Definitely assigned
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2025, 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+
/// @assertion `assigned` is a boolean value indicating whether the variable has
6+
/// definitely been assigned at the given point in the source code. When
7+
/// `assigned` is true, we say that the variable is definitely assigned at that
8+
/// point.
9+
///
10+
/// @description Checks definite assignment via object pattern assignment.
11+
/// @author [email protected]
12+
13+
class C {
14+
int x;
15+
C(this.x);
16+
}
17+
18+
main() {
19+
int n;
20+
C(x: n) = C(42);
21+
n; // Definitely assigned
22+
}

0 commit comments

Comments
 (0)