OLD | NEW |
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 /// General type checking tests | 5 /// General type checking tests |
6 library dev_compiler.test.checker_test; | 6 library dev_compiler.test.checker_test; |
7 | 7 |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 | 9 |
10 import '../testing.dart'; | 10 import '../testing.dart'; |
(...skipping 2746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2757 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); } | 2757 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); } |
2758 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab
le<int>()); } | 2758 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab
le<int>()); } |
2759 | 2759 |
2760 baz1() sync* { yield* (/*info:DynamicCast*/x); } | 2760 baz1() sync* { yield* (/*info:DynamicCast*/x); } |
2761 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } | 2761 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } |
2762 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } | 2762 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } |
2763 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2763 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
2764 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } | 2764 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } |
2765 ''' | 2765 ''' |
2766 })); | 2766 })); |
| 2767 |
| 2768 test( |
| 2769 'dart:math min/max', |
| 2770 () => testChecker({ |
| 2771 '/main.dart': ''' |
| 2772 import 'dart:math'; |
| 2773 |
| 2774 void printInt(int x) => print(x); |
| 2775 void printDouble(double x) => print(x); |
| 2776 |
| 2777 num myMax(num x, num y) => max(x, y); |
| 2778 |
| 2779 main() { |
| 2780 // Okay if static types match. |
| 2781 printInt(max(1, 2)); |
| 2782 printInt(min(1, 2)); |
| 2783 printDouble(max(1.0, 2.0)); |
| 2784 printDouble(min(1.0, 2.0)); |
| 2785 |
| 2786 // No help for user-defined functions from num->num->num. |
| 2787 printInt(/*warning:DownCastImplicit*/myMax(1, 2)); |
| 2788 printInt(myMax(1, 2) as int); |
| 2789 |
| 2790 // Mixing int and double means return type is num. |
| 2791 printInt(/*warning:DownCastImplicit*/max(1, 2.0)); |
| 2792 printInt(/*warning:DownCastImplicit*/min(1, 2.0)); |
| 2793 printDouble(/*warning:DownCastImplicit*/max(1, 2.0)); |
| 2794 printDouble(/*warning:DownCastImplicit*/min(1, 2.0)); |
| 2795 |
| 2796 // Types other than int and double are not accepted. |
| 2797 printInt( |
| 2798 /*warning:DownCastImplicit*/min( |
| 2799 /*severe:StaticTypeError*/"hi", |
| 2800 /*severe:StaticTypeError*/"there")); |
| 2801 } |
| 2802 ''' |
| 2803 })); |
2767 }); | 2804 }); |
2768 } | 2805 } |
OLD | NEW |