OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
7 import 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
8 import 'type_mask_test_helper.dart'; | 8 import 'type_mask_test_helper.dart'; |
9 | 9 |
10 | |
11 | |
12 const String TEST = """ | 10 const String TEST = """ |
13 | 11 |
14 // [defaultFn_i] is called only via [foo_i]'s default value with a small integer . | 12 // [defaultFn_i] is called only via [foo_i]'s default value with a small integer . |
15 | 13 |
16 defaultFn1(a) => a; | 14 defaultFn1(a) => a; |
17 defaultFn2(a) => a; | 15 defaultFn2(a) => a; |
18 defaultFn3(a) => a; | 16 defaultFn3(a) => a; |
19 defaultFn4(a) => a; | 17 defaultFn4(a) => a; |
20 defaultFn5(a) => a; | 18 defaultFn5(a) => a; |
21 defaultFn6(a) => a; | 19 defaultFn6(a) => a; |
(...skipping 11 matching lines...) Expand all Loading... | |
33 foo2(); | 31 foo2(); |
34 // Indirect calls. | 32 // Indirect calls. |
35 (foo3)(); | 33 (foo3)(); |
36 (foo4)(); | 34 (foo4)(); |
37 // Calls via Function.apply. | 35 // Calls via Function.apply. |
38 Function.apply(foo5, []); | 36 Function.apply(foo5, []); |
39 Function.apply(foo6, []); | 37 Function.apply(foo6, []); |
40 } | 38 } |
41 """; | 39 """; |
42 | 40 |
43 | |
44 void main() { | 41 void main() { |
45 Uri uri = new Uri(scheme: 'source'); | 42 Uri uri = new Uri(scheme: 'source'); |
46 var compiler = compilerFor(TEST, uri); | 43 var compiler = compilerFor(TEST, uri); |
47 asyncTest(() => compiler.run(uri).then((_) { | 44 asyncTest(() => compiler.run(uri).then((_) { |
48 var typesInferrer = compiler.globalInference.typesInferrer; | 45 var typesInferrer = compiler.globalInference.typesInferrer; |
49 | 46 |
50 checkArgument(String functionName, type) { | 47 checkArgument(String functionName, type) { |
51 var functionElement = findElement(compiler, functionName); | 48 var functionElement = findElement(compiler, functionName); |
52 var signature = functionElement.functionSignature; | 49 var signature = functionElement.functionSignature; |
53 var element = signature.requiredParameterCount > 0 | 50 var element = signature.requiredParameterCount > 0 |
54 ? signature.requiredParameters.first | 51 ? signature.requiredParameters.first |
55 : signature.optionalParameters.first; | 52 : signature.optionalParameters.first; |
56 Expect.equals(type, | 53 Expect.equals( |
57 simplify(typesInferrer.getTypeOfElement(element), compiler), | 54 type, |
58 functionName); | 55 simplify(typesInferrer.getTypeOfElement(element), compiler), |
59 } | 56 functionName); |
57 } | |
60 | 58 |
61 checkOptionalArgument(String functionName, type) { | 59 checkOptionalArgument(String functionName, type) { |
62 var functionElement = findElement(compiler, functionName); | 60 var functionElement = findElement(compiler, functionName); |
63 var signature = functionElement.functionSignature; | 61 var signature = functionElement.functionSignature; |
64 var element = signature.optionalParameters.first; | 62 var element = signature.optionalParameters.first; |
65 Expect.equals(type, | 63 Expect.equals( |
66 simplify(typesInferrer.getTypeOfElement(element), compiler), | 64 type, |
67 functionName); | 65 simplify(typesInferrer.getTypeOfElement(element), compiler), |
68 } | 66 functionName); |
67 } | |
69 | 68 |
70 checkArgument('foo1', compiler.commonMasks.functionType); /// 01: ok | 69 checkArgument('foo1', compiler.commonMasks.functionType); |
71 checkArgument('foo2', compiler.commonMasks.functionType); /// 02: ok | |
72 checkArgument('foo3', compiler.commonMasks.functionType); /// 03: ok | |
73 checkArgument('foo4', compiler.commonMasks.functionType); /// 04: ok | |
74 checkArgument('foo5', compiler.commonMasks.dynamicType); /// 05: ok | |
75 checkArgument('foo6', compiler.commonMasks.dynamicType); /// 06: ok | |
76 | 70 |
77 checkArgument('defaultFn1', compiler.commonMasks.uint31Type); /// 07: ok | 71 /// 01: ok |
Siggi Cherem (dart-lang)
2016/09/16 20:55:23
revert => this changes the semantics of the multi-
Harry Terkelsen
2016/09/16 21:44:04
Done.
| |
78 checkArgument('defaultFn2', compiler.commonMasks.uint31Type); /// 08: ok | 72 checkArgument('foo2', compiler.commonMasks.functionType); |
79 checkArgument('defaultFn3', compiler.commonMasks.uint31Type); /// 09: ok | 73 |
80 checkArgument('defaultFn4', compiler.commonMasks.uint31Type); /// 10: ok | 74 /// 02: ok |
81 checkArgument('defaultFn5', compiler.commonMasks.uint31Type); /// 11: ok | 75 checkArgument('foo3', compiler.commonMasks.functionType); |
82 checkArgument('defaultFn6', compiler.commonMasks.uint31Type); /// 12: ok | 76 |
83 })); | 77 /// 03: ok |
78 checkArgument('foo4', compiler.commonMasks.functionType); | |
79 | |
80 /// 04: ok | |
81 checkArgument('foo5', compiler.commonMasks.dynamicType); | |
82 | |
83 /// 05: ok | |
84 checkArgument('foo6', compiler.commonMasks.dynamicType); | |
85 | |
86 /// 06: ok | |
87 | |
88 checkArgument('defaultFn1', compiler.commonMasks.uint31Type); | |
89 | |
90 /// 07: ok | |
91 checkArgument('defaultFn2', compiler.commonMasks.uint31Type); | |
92 | |
93 /// 08: ok | |
94 checkArgument('defaultFn3', compiler.commonMasks.uint31Type); | |
95 | |
96 /// 09: ok | |
97 checkArgument('defaultFn4', compiler.commonMasks.uint31Type); | |
98 | |
99 /// 10: ok | |
100 checkArgument('defaultFn5', compiler.commonMasks.uint31Type); | |
101 | |
102 /// 11: ok | |
103 checkArgument('defaultFn6', compiler.commonMasks.uint31Type); | |
104 | |
105 /// 12: ok | |
106 })); | |
84 } | 107 } |
OLD | NEW |