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:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 import 'package:dev_compiler/src/testing.dart'; | 10 import 'package:dev_compiler/src/testing.dart'; |
11 | 11 |
12 import '../test_util.dart'; | 12 import '../test_util.dart'; |
13 | 13 |
14 void main() { | 14 void main() { |
15 configureTest(); | 15 configureTest(); |
16 | 16 |
17 test('conversion and dynamic invoke', () { | 17 test('conversion and dynamic invoke', () { |
18 testChecker({ | 18 testChecker({ |
| 19 '/helper.dart': ''' |
| 20 dynamic toString = (int x) => x + 42; |
| 21 dynamic hashCode = "hello"; |
| 22 ''', |
19 '/main.dart': ''' | 23 '/main.dart': ''' |
| 24 import 'helper.dart' as helper; |
| 25 |
20 class A { | 26 class A { |
21 String x = "hello world"; | 27 String x = "hello world"; |
22 | 28 |
23 void baz1(y) => x + y; | 29 void baz1(y) => x + y; |
24 static baz2(y) => y + y; | 30 static baz2(y) => y + y; |
25 } | 31 } |
26 | 32 |
27 void foo(String str) { | 33 void foo(String str) { |
28 print(str); | 34 print(str); |
29 } | 35 } |
30 | 36 |
| 37 class B { |
| 38 String toString([int arg]) => arg.toString(); |
| 39 } |
| 40 |
31 void bar(a) { | 41 void bar(a) { |
32 foo(/*info:DynamicCast,info:DynamicInvoke*/a.x); | 42 foo(/*info:DynamicCast,info:DynamicInvoke*/a.x); |
33 } | 43 } |
34 | 44 |
35 typedef DynFun(x); | 45 typedef DynFun(x); |
36 typedef StrFun(String x); | 46 typedef StrFun(String x); |
37 | 47 |
38 var bar1 = bar; | 48 var bar1 = bar; |
39 | 49 |
40 void main() { | 50 void main() { |
(...skipping 10 matching lines...) Expand all Loading... |
51 (/*info:DynamicInvoke*/f3("hello")); | 61 (/*info:DynamicInvoke*/f3("hello")); |
52 (/*info:DynamicInvoke*/f3(42)); | 62 (/*info:DynamicInvoke*/f3(42)); |
53 StrFun f4 = foo; | 63 StrFun f4 = foo; |
54 f4("hello"); | 64 f4("hello"); |
55 a.baz1("hello"); | 65 a.baz1("hello"); |
56 var b1 = a.baz1; | 66 var b1 = a.baz1; |
57 (/*info:DynamicInvoke*/b1("hello")); | 67 (/*info:DynamicInvoke*/b1("hello")); |
58 A.baz2("hello"); | 68 A.baz2("hello"); |
59 var b2 = A.baz2; | 69 var b2 = A.baz2; |
60 (/*info:DynamicInvoke*/b2("hello")); | 70 (/*info:DynamicInvoke*/b2("hello")); |
| 71 |
| 72 dynamic a1 = new B(); |
| 73 (/*info:DynamicInvoke*/a1.x); |
| 74 a1.toString(); |
| 75 (/*info:DynamicInvoke*/a1.toString(42)); |
| 76 var toStringClosure = a1.toString; |
| 77 (/*info:DynamicInvoke*/a1.toStringClosure()); |
| 78 (/*info:DynamicInvoke*/a1.toStringClosure(42)); |
| 79 (/*info:DynamicInvoke*/a1.toStringClosure("hello")); |
| 80 a1.hashCode; |
| 81 |
| 82 dynamic toString = () => null; |
| 83 (/*info:DynamicInvoke*/toString()); |
| 84 |
| 85 (/*info:DynamicInvoke*/helper.toString()); |
| 86 var toStringClosure2 = helper.toString; |
| 87 (/*info:DynamicInvoke*/toStringClosure2()); |
| 88 int hashCode = /*info:DynamicCast*/helper.hashCode; |
61 ''' | 89 ''' |
62 }); | 90 }); |
63 }); | 91 }); |
64 | 92 |
65 test('Primitives', () { | 93 test('Primitives', () { |
66 testChecker({ | 94 testChecker({ |
67 '/main.dart': ''' | 95 '/main.dart': ''' |
68 int /*severe:InvalidVariableDeclaration*/a; | 96 int /*severe:InvalidVariableDeclaration*/a; |
69 double /*severe:InvalidVariableDeclaration*/b; | 97 double /*severe:InvalidVariableDeclaration*/b; |
70 num c; | 98 num c; |
(...skipping 2728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2799 f = bar as II2D; | 2827 f = bar as II2D; |
2800 f = bar as DD2I; | 2828 f = bar as DD2I; |
2801 f = bar as DI2D; | 2829 f = bar as DI2D; |
2802 f = bar as ID2D; | 2830 f = bar as ID2D; |
2803 f = bar as DD2D; | 2831 f = bar as DD2D; |
2804 } | 2832 } |
2805 ''' | 2833 ''' |
2806 }); | 2834 }); |
2807 }); | 2835 }); |
2808 } | 2836 } |
OLD | NEW |