OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 // Evaluation of an if-null expression e of the form e1 ?? e2 is equivalent to | |
6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1). | |
7 // | |
8 // Therefore, e1 should be evaluated first; if it is non-null, e2 should not | |
9 // be evaluated. | |
10 | |
11 import "package:expect/expect.dart"; | |
12 | |
13 void bad() { | |
14 throw new Exception(); | |
15 } | |
16 | |
17 bool firstExecuted = false; | |
18 | |
19 first() { | |
20 firstExecuted = true; | |
21 return null; | |
22 } | |
23 | |
24 second() { | |
25 Expect.isTrue(firstExecuted); | |
26 return 2; | |
27 } | |
28 | |
29 main() { | |
30 // Make sure the "none" test fails if "??" is not implemented. This makes | |
31 // status files easier to maintain. | |
32 var _ = null ?? null; | |
33 | |
34 Expect.equals(1, 1 ?? bad()); //# 01: ok | |
35 Expect.equals(2, first() ?? second()); //# 02: ok | |
36 } | |
OLD | NEW |