| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011, 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 import "package:expect/expect.dart"; |
| 6 |
| 7 // Test for correct order of exceptions in code with checks that could be moved |
| 8 // merged from successors into a dominator. |
| 9 |
| 10 get never => new DateTime.now().millisecondsSinceEpoch == 42; |
| 11 get always => new DateTime.now().millisecondsSinceEpoch > 42; |
| 12 |
| 13 // gA and gB have type [null|num], so they compile to a receiver check, and |
| 14 // argument check and then the operation. |
| 15 var gA; // [null|num] |
| 16 var gB; // [null|num] |
| 17 |
| 18 foo1(a, b) { |
| 19 // The checks on a and b are not equivalent, so can't be merged. |
| 20 if (never) { |
| 21 return a ^ b; |
| 22 } else { |
| 23 return b ^ a; |
| 24 } |
| 25 } |
| 26 |
| 27 call1() { return foo1(gA, gB); } |
| 28 |
| 29 test1() { |
| 30 gA = 1; |
| 31 gB = 2; |
| 32 Expect.equals(3, call1()); |
| 33 |
| 34 gA = null; |
| 35 gB = null; |
| 36 Expect.throws(call1, (e) => e is NoSuchMethodError, 'foo1($gA, $gB) NSME'); |
| 37 |
| 38 gA = 1; |
| 39 gB = null; |
| 40 Expect.throws(call1, (e) => e is NoSuchMethodError, 'foo1($gA, $gB) NSME'); |
| 41 |
| 42 gA = null; |
| 43 gB = 2; |
| 44 Expect.throws(call1, (e) => e is ArgumentError, 'foo1($gA, $gB) AE'); |
| 45 } |
| 46 |
| 47 |
| 48 foo2a(a, b) { |
| 49 // The common receiver check on [a] cannot be merged because the operation |
| 50 // (selector) is different. |
| 51 // The common argument check on [b] cannot be merged because it must happen |
| 52 // after the receiver check. |
| 53 if (never) { |
| 54 return a ^ b; |
| 55 } else { |
| 56 return a & b; |
| 57 } |
| 58 } |
| 59 |
| 60 foo2b(a, b) { |
| 61 // Same a foo2a except which branch dynamically taken. |
| 62 if (always) { |
| 63 return a ^ b; |
| 64 } else { |
| 65 return a & b; |
| 66 } |
| 67 } |
| 68 |
| 69 call2a() { return foo2a(gA, gB); } |
| 70 call2b() { return foo2b(gA, gB); } |
| 71 |
| 72 checkNSME(text) { |
| 73 return (e) { |
| 74 Expect.isTrue(e is NoSuchMethodError, |
| 75 'expecting NoSuchMethodError, got "${e.runtimeType}"'); |
| 76 Expect.isTrue('$e'.contains(text), '"$e".contains("$text")'); |
| 77 return e is NoSuchMethodError; |
| 78 }; |
| 79 } |
| 80 |
| 81 test2() { |
| 82 gA = 1; |
| 83 gB = 2; |
| 84 Expect.equals(0, call2a()); |
| 85 Expect.equals(3, call2b()); |
| 86 |
| 87 gA = null; |
| 88 gB = null; |
| 89 Expect.throws(call2a, checkNSME(r'$and'), 'foo2($gA, $gB) NSME'); |
| 90 Expect.throws(call2b, checkNSME(r'$xor'), 'foo2($gA, $gB) NSME'); |
| 91 |
| 92 gA = 1; |
| 93 gB = null; |
| 94 Expect.throws(call2a, (e) => e is ArgumentError, 'foo2($gA, $gB) AE'); |
| 95 Expect.throws(call2b, (e) => e is ArgumentError, 'foo2($gA, $gB) AE'); |
| 96 |
| 97 gA = null; |
| 98 gB = 2; |
| 99 Expect.throws(call2a, checkNSME(r'$and'), 'foo2($gA, $gB) NSME'); |
| 100 Expect.throws(call2b, checkNSME(r'$xor'), 'foo2($gA, $gB) NSME'); |
| 101 } |
| 102 |
| 103 main() { |
| 104 test1(); |
| 105 test2(); |
| 106 } |
| OLD | NEW |