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 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 }''' | 2668 }''' |
2669 }, | 2669 }, |
2670 customUrlMappings: { | 2670 customUrlMappings: { |
2671 'dart:foobar': '$testDirectory/checker/dart_foobar.dart' | 2671 'dart:foobar': '$testDirectory/checker/dart_foobar.dart' |
2672 })); | 2672 })); |
2673 | 2673 |
2674 group('function modifiers', () { | 2674 group('function modifiers', () { |
2675 test('async', () => testChecker({ | 2675 test('async', () => testChecker({ |
2676 '/main.dart': ''' | 2676 '/main.dart': ''' |
2677 import 'dart:async'; | 2677 import 'dart:async'; |
| 2678 import 'dart:math' show Random; |
2678 | 2679 |
2679 dynamic x; | 2680 dynamic x; |
2680 | 2681 |
2681 foo1() async => x; | 2682 foo1() async => x; |
2682 Future foo2() async => x; | 2683 Future foo2() async => x; |
2683 Future<int> foo3() async => (/*info:DynamicCast*/x); | 2684 Future<int> foo3() async => (/*info:DynamicCast*/x); |
2684 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>(x
)); | 2685 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>.v
alue(/*info:DynamicCast*/x)); |
2685 | 2686 |
2686 bar1() async { return x; } | 2687 bar1() async { return x; } |
2687 Future bar2() async { return x; } | 2688 Future bar2() async { return x; } |
2688 Future<int> bar3() async { return (/*info:DynamicCast*/x); } | 2689 Future<int> bar3() async { return (/*info:DynamicCast*/x); } |
2689 Future<int> bar4() async { return (/*severe:StaticTypeError*/new Future<
int>(x)); } | 2690 Future<int> bar4() async { return (/*severe:StaticTypeError*/new Future<
int>.value(/*info:DynamicCast*/x)); } |
2690 | 2691 |
2691 int y; | 2692 int y; |
2692 Future<int> z; | 2693 Future<int> z; |
2693 | 2694 |
2694 void baz() async { | 2695 void baz() async { |
2695 int a = /*info:DynamicCast*/await x; | 2696 int a = /*info:DynamicCast*/await x; |
2696 int b = await y; | 2697 int b = await y; |
2697 int c = await z; | 2698 int c = await z; |
2698 String d = /*severe:StaticTypeError*/await z; | 2699 String d = /*severe:StaticTypeError*/await z; |
2699 } | 2700 } |
2700 | 2701 |
2701 Future<bool> get issue_264 async { | 2702 Future<bool> get issue_264 async { |
2702 await 42; | 2703 await 42; |
2703 return false; | 2704 if (new Random().nextBool()) { |
| 2705 return true; |
| 2706 } else { |
| 2707 return /*severe:StaticTypeError*/new Future<bool>.value(false); |
| 2708 } |
2704 } | 2709 } |
2705 ''' | 2710 ''' |
2706 })); | 2711 })); |
2707 | 2712 |
2708 test('async*', () => testChecker({ | 2713 test('async*', () => testChecker({ |
2709 '/main.dart': ''' | 2714 '/main.dart': ''' |
2710 import 'dart:async'; | 2715 import 'dart:async'; |
2711 | 2716 |
2712 dynamic x; | 2717 dynamic x; |
2713 | 2718 |
(...skipping 23 matching lines...) Expand all Loading... |
2737 | 2742 |
2738 baz1() sync* { yield* (/*info:DynamicCast*/x); } | 2743 baz1() sync* { yield* (/*info:DynamicCast*/x); } |
2739 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } | 2744 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } |
2740 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } | 2745 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } |
2741 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2746 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
2742 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } | 2747 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new
Iterable()); } |
2743 ''' | 2748 ''' |
2744 })); | 2749 })); |
2745 }); | 2750 }); |
2746 } | 2751 } |
OLD | NEW |