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 import "package:expect/expect.dart"; |
| 6 |
| 7 // Test that optimized '-' and slow path '-' produce the same error. |
| 8 |
| 9 @NoInline() |
| 10 @AssumeDynamic() |
| 11 confuse(x) => x; |
| 12 |
| 13 void check2(String name, name1, f1, name2, f2) { |
| 14 Error trap(part, f) { |
| 15 try { |
| 16 f(); |
| 17 } catch (e) { |
| 18 return e; |
| 19 } |
| 20 Expect.fail('should throw: $name.$part'); |
| 21 } |
| 22 var e1 = trap(name1, f1); |
| 23 var e2 = trap(name2, f2); |
| 24 var s1 = '$e1'; |
| 25 var s2 = '$e2'; |
| 26 Expect.equals(s1, s2, '\n $name.$name1: "$s1"\n $name.$name2: "$s2"\n'); |
| 27 } |
| 28 |
| 29 void check(String name, f1, f2, [f3, f4, f5, f6, f7]) { |
| 30 check2(name, 'f1', f1, 'f2', f2); |
| 31 if (f3 != null) check2(name, 'f1', f1, 'f3', f3); |
| 32 if (f4 != null) check2(name, 'f1', f1, 'f4', f4); |
| 33 if (f5 != null) check2(name, 'f1', f1, 'f5', f5); |
| 34 if (f6 != null) check2(name, 'f1', f1, 'f6', f6); |
| 35 if (f7 != null) check2(name, 'f1', f1, 'f7', f7); |
| 36 } |
| 37 |
| 38 class IntMinusNull { |
| 39 static f1() { |
| 40 return confuse(1) - confuse(null); |
| 41 } |
| 42 |
| 43 static f2() { |
| 44 return confuse(1) - null; |
| 45 } |
| 46 |
| 47 static f3() { |
| 48 return (confuse(1) as int) - confuse(null); |
| 49 } |
| 50 |
| 51 static f4() { |
| 52 return (confuse(1) as int) - null; |
| 53 } |
| 54 |
| 55 static f5() { |
| 56 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
| 57 return a - confuse(null); |
| 58 } |
| 59 |
| 60 static f6() { |
| 61 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
| 62 return a - null; |
| 63 } |
| 64 |
| 65 static f7() { |
| 66 return 1 - null; |
| 67 } |
| 68 |
| 69 static test() { |
| 70 check('IntMinusNull', f1, f2, f3, f4, f5, f6, f7); |
| 71 } |
| 72 } |
| 73 |
| 74 class IntMinusString { |
| 75 static f1() { |
| 76 return confuse(1) - confuse('a'); |
| 77 } |
| 78 |
| 79 static f2() { |
| 80 return confuse(1) - 'a'; |
| 81 } |
| 82 |
| 83 static f3() { |
| 84 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
| 85 return a - confuse('a'); |
| 86 } |
| 87 |
| 88 static f4() { |
| 89 return (confuse(1) as int) - confuse('a'); |
| 90 } |
| 91 |
| 92 static f5() { |
| 93 return (confuse(1) as int) - 'a'; |
| 94 } |
| 95 |
| 96 static f6() { |
| 97 var a = confuse(true) ? 1 : 2; // Small int with unknown value. |
| 98 return a - 'a'; |
| 99 } |
| 100 |
| 101 static f7() { |
| 102 return 1 - 'a'; |
| 103 } |
| 104 |
| 105 static test() { |
| 106 check('IntMinusString', f1, f2, f3, f4, f5, f6, f7); |
| 107 } |
| 108 } |
| 109 |
| 110 main() { |
| 111 IntMinusNull.test(); |
| 112 IntMinusString.test(); |
| 113 } |
OLD | NEW |