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 |
| 45 baz() => new B(); |
| 46 |
35 typedef DynFun(x); | 47 typedef DynFun(x); |
36 typedef StrFun(String x); | 48 typedef StrFun(String x); |
37 | 49 |
38 var bar1 = bar; | 50 var bar1 = bar; |
39 | 51 |
40 void main() { | 52 void main() { |
41 var a = new A(); | 53 var a = new A(); |
42 bar(a); | 54 bar(a); |
43 (/*info:DynamicInvoke*/bar1(a)); | 55 (/*info:DynamicInvoke*/bar1(a)); |
44 var b = bar; | 56 var b = bar; |
45 (/*info:DynamicInvoke*/b(a)); | 57 (/*info:DynamicInvoke*/b(a)); |
46 var f1 = foo; | 58 var f1 = foo; |
47 f1("hello"); | 59 f1("hello"); |
48 dynamic f2 = foo; | 60 dynamic f2 = foo; |
49 (/*info:DynamicInvoke*/f2("hello")); | 61 (/*info:DynamicInvoke*/f2("hello")); |
50 DynFun f3 = foo; | 62 DynFun f3 = foo; |
51 (/*info:DynamicInvoke*/f3("hello")); | 63 (/*info:DynamicInvoke*/f3("hello")); |
52 (/*info:DynamicInvoke*/f3(42)); | 64 (/*info:DynamicInvoke*/f3(42)); |
53 StrFun f4 = foo; | 65 StrFun f4 = foo; |
54 f4("hello"); | 66 f4("hello"); |
55 a.baz1("hello"); | 67 a.baz1("hello"); |
56 var b1 = a.baz1; | 68 var b1 = a.baz1; |
57 (/*info:DynamicInvoke*/b1("hello")); | 69 (/*info:DynamicInvoke*/b1("hello")); |
58 A.baz2("hello"); | 70 A.baz2("hello"); |
59 var b2 = A.baz2; | 71 var b2 = A.baz2; |
60 (/*info:DynamicInvoke*/b2("hello")); | 72 (/*info:DynamicInvoke*/b2("hello")); |
| 73 |
| 74 dynamic a1 = new B(); |
| 75 (/*info:DynamicInvoke*/a1.x); |
| 76 a1.toString(); |
| 77 (/*info:DynamicInvoke*/a1.toString(42)); |
| 78 var toStringClosure = a1.toString; |
| 79 (/*info:DynamicInvoke*/a1.toStringClosure()); |
| 80 (/*info:DynamicInvoke*/a1.toStringClosure(42)); |
| 81 (/*info:DynamicInvoke*/a1.toStringClosure("hello")); |
| 82 a1.hashCode; |
| 83 |
| 84 dynamic toString = () => null; |
| 85 (/*info:DynamicInvoke*/toString()); |
| 86 |
| 87 (/*info:DynamicInvoke*/helper.toString()); |
| 88 var toStringClosure2 = helper.toString; |
| 89 (/*info:DynamicInvoke*/toStringClosure2()); |
| 90 int hashCode = /*info:DynamicCast*/helper.hashCode; |
| 91 |
| 92 baz().toString(); |
| 93 baz().hashCode; |
61 ''' | 94 ''' |
62 }); | 95 }); |
63 }); | 96 }); |
64 | 97 |
65 test('Primitives', () { | 98 test('Primitives', () { |
66 testChecker({ | 99 testChecker({ |
67 '/main.dart': ''' | 100 '/main.dart': ''' |
68 int /*severe:InvalidVariableDeclaration*/a; | 101 int /*severe:InvalidVariableDeclaration*/a; |
69 double /*severe:InvalidVariableDeclaration*/b; | 102 double /*severe:InvalidVariableDeclaration*/b; |
70 num c; | 103 num c; |
(...skipping 2728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2799 f = bar as II2D; | 2832 f = bar as II2D; |
2800 f = bar as DD2I; | 2833 f = bar as DD2I; |
2801 f = bar as DI2D; | 2834 f = bar as DI2D; |
2802 f = bar as ID2D; | 2835 f = bar as ID2D; |
2803 f = bar as DD2D; | 2836 f = bar as DD2D; |
2804 } | 2837 } |
2805 ''' | 2838 ''' |
2806 }); | 2839 }); |
2807 }); | 2840 }); |
2808 } | 2841 } |
OLD | NEW |