File tree Expand file tree Collapse file tree 6 files changed +126
-8
lines changed
Language/Expressions/Unary_Expressions Expand file tree Collapse file tree 6 files changed +126
-8
lines changed Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- /// @assertion Evaluation of an expression of the form --e is equivalent to
6
- /// e -= 1.
5
+ /// @assertion An expression of the form ` --e` is treated as `(e-=1)` .
6
+ ///
7
7
/// @description Checks that evaluation of an expression of the form --e is
8
8
/// equivalent to e -= 1.
9
9
/// @author msyabro
Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- /// @assertion Evaluation of an expression of the form --e is equivalent to
6
- /// e -= 1.
5
+ /// @assertion An expression of the form ` --e` is treated as `(e-=1)` .
6
+ ///
7
7
/// @description Checks that evaluation of an expression of the form --e
8
8
/// results in invoking operator- on the result of e with the proper argument.
9
9
/// @author rodionov
Original file line number Diff line number Diff line change
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 An expression of the form `--e` is treated as `(e-=1)` .
6
+ ///
7
+ /// @description Checks that evaluation of an expression of the form `--e`
8
+ /// results in invoking `operator-` on the result of `e` with the proper
9
+ /// argument. Test nullable types.
10
+
11
+ /// @issue 56963
12
+
13
+ import '../../../Utils/expect.dart' ;
14
+
15
+ class A {
16
+ final int value;
17
+ A (this .value);
18
+
19
+ A ? operator - (int ? other) {
20
+ if (other != null ) {
21
+ return A (value - other);
22
+ }
23
+ return null ;
24
+ }
25
+ }
26
+
27
+ extension on A ? {
28
+ A ? operator - (int other) {
29
+ if (this != null ) {
30
+ return this ! - other;
31
+ }
32
+ return null ;
33
+ }
34
+ }
35
+
36
+ extension on int ? {
37
+ int ? operator - (int ? other) {
38
+ if (this != null && other != null ) {
39
+ return this ! - other;
40
+ }
41
+ return null ;
42
+ }
43
+ }
44
+
45
+ main () {
46
+ A ? a = 2 > 1 ? A (42 ) : null ;
47
+ var x = -- a ?? A (- 1 );
48
+ Expect .equals (41 , x.value);
49
+ a = 2 > 3 ? A (42 ) : null ;
50
+ x = -- a ?? A (- 1 );
51
+ Expect .equals (- 1 , x.value);
52
+
53
+ int ? i = 2 > 1 ? 42 : null ;
54
+ var y = -- i ?? - 1 ;
55
+ Expect .equals (41 , y);
56
+ i = 2 > 3 ? 42 : null ;
57
+ y = -- i ?? - 1 ;
58
+ Expect .equals (- 1 , y);
59
+ }
Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- /// @assertion Evaluation of an expression of the form ++e is equivalent to
6
- /// e += 1.
5
+ /// @assertion An expression of the form ` ++e` is treated as `(e+=1)` .
6
+ ///
7
7
/// @description Checks that evaluation of an expression of the form ++e is
8
8
/// equivalent to e += 1.
9
9
/// @author msyabro
Original file line number Diff line number Diff line change 2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- /// @assertion Evaluation of an expression of the form ++e is equivalent to
6
- /// e += 1.
5
+ /// @assertion An expression of the form ` ++e` is treated as `(e+=1)` .
6
+ ///
7
7
/// @description Checks that evaluation of an expression of the form ++e
8
8
/// results in invoking operator+ on the result of e with the proper argument.
9
9
/// @author rodionov
Original file line number Diff line number Diff line change
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 An expression of the form `++e` is treated as `(e+=1)` .
6
+ ///
7
+ /// @description Checks that evaluation of an expression of the form `++e`
8
+ /// results in invoking `operator+` on the result of e with the proper argument.
9
+ /// Test nullable types.
10
+
11
+ /// @issue 56963
12
+
13
+ import '../../../Utils/expect.dart' ;
14
+
15
+ class A {
16
+ final int value;
17
+ A (this .value);
18
+
19
+ A ? operator + (int ? other) {
20
+ if (other != null ) {
21
+ return A (value + other);
22
+ }
23
+ return null ;
24
+ }
25
+ }
26
+
27
+ extension on A ? {
28
+ A ? operator + (int other) {
29
+ if (this != null ) {
30
+ return this ! + other;
31
+ }
32
+ return null ;
33
+ }
34
+ }
35
+
36
+ extension on int ? {
37
+ int ? operator + (int ? other) {
38
+ if (this != null && other != null ) {
39
+ return this ! + other;
40
+ }
41
+ return null ;
42
+ }
43
+ }
44
+
45
+ main () {
46
+ A ? a = 2 > 1 ? A (1 ) : null ;
47
+ var x = ++ a ?? A (- 1 );
48
+ Expect .equals (2 , x.value);
49
+ a = 2 > 3 ? A (1 ) : null ;
50
+ x = ++ a ?? A (- 1 );
51
+ Expect .equals (- 1 , x.value);
52
+
53
+ int ? i = 2 > 1 ? 42 : null ;
54
+ var y = ++ i ?? - 1 ;
55
+ Expect .equals (43 , y);
56
+ i = 2 > 3 ? 42 : null ;
57
+ y = ++ i ?? - 1 ;
58
+ Expect .equals (- 1 , y);
59
+ }
You can’t perform that action at this time.
0 commit comments