Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tests/language/if_null_evaluation_order_test.dart

Issue 1239513005: Switch on null-aware operators by default in analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/language/if_null_behavior_test.dart ('k') | tests/language/if_null_precedence_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Evaluation of an if-null expresion e of the form e1 ?? e2 is equivalent to 5 // Evaluation of an if-null expresion e of the form e1 ?? e2 is equivalent to
6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1). 6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1).
7 // 7 //
8 // Therefore, e1 should be evaluated first; if it is non-null, e2 should not 8 // Therefore, e1 should be evaluated first; if it is non-null, e2 should not
9 // be evaluated. 9 // be evaluated.
10 10
11 // SharedOptions=--enable-null-aware-operators
12
13 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
14 12
15 void bad() { 13 void bad() {
16 throw new Exception(); 14 throw new Exception();
17 } 15 }
18 16
19 bool firstExecuted = false; 17 bool firstExecuted = false;
20 18
21 first() { 19 first() {
22 firstExecuted = true; 20 firstExecuted = true;
23 return null; 21 return null;
24 } 22 }
25 23
26 second() { 24 second() {
27 Expect.isTrue(firstExecuted); 25 Expect.isTrue(firstExecuted);
28 return 2; 26 return 2;
29 } 27 }
30 28
31 main() { 29 main() {
32 // Make sure the "none" test fails if "??" is not implemented. This makes 30 // Make sure the "none" test fails if "??" is not implemented. This makes
33 // status files easier to maintain. 31 // status files easier to maintain.
34 var _ = null ?? null; 32 var _ = null ?? null;
35 33
36 Expect.equals(1, 1 ?? bad()); /// 01: ok 34 Expect.equals(1, 1 ?? bad()); /// 01: ok
37 Expect.equals(2, first() ?? second()); /// 02: ok 35 Expect.equals(2, first() ?? second()); /// 02: ok
38 } 36 }
OLDNEW
« no previous file with comments | « tests/language/if_null_behavior_test.dart ('k') | tests/language/if_null_precedence_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698