OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
7 import 'parser_helper.dart'; | 8 import 'parser_helper.dart'; |
8 | 9 |
9 const String TEST = """ | 10 const String TEST = """ |
10 | 11 |
11 class A { | 12 class A { |
12 final intField; | 13 final intField; |
13 final giveUpField1; | 14 final giveUpField1; |
14 final giveUpField2; | 15 final giveUpField2; |
15 final fieldParameter; | 16 final fieldParameter; |
16 A() : intField = 42, giveUpField1 = 'foo', giveUpField2 = 'foo'; | 17 A() : intField = 42, giveUpField1 = 'foo', giveUpField2 = 'foo'; |
17 A.bar() : intField = 54, giveUpField1 = 42, giveUpField2 = new A(); | 18 A.bar() : intField = 54, giveUpField1 = 42, giveUpField2 = new A(); |
18 A.foo(this.fieldParameter); | 19 A.foo(this.fieldParameter); |
19 } | 20 } |
20 | 21 |
21 main() { | 22 main() { |
22 new A(); | 23 new A(); |
23 new A.bar(); | 24 new A.bar(); |
24 new A.foo(42); | 25 new A.foo(42); |
25 } | 26 } |
26 """; | 27 """; |
27 | 28 |
28 void main() { | 29 void main() { |
29 Uri uri = new Uri(scheme: 'source'); | 30 Uri uri = new Uri(scheme: 'source'); |
30 var compiler = compilerFor(TEST, uri); | 31 var compiler = compilerFor(TEST, uri); |
31 compiler.runCompiler(uri); | 32 asyncTest(() => compiler.runCompiler(uri).then((_) { |
32 var typesInferrer = compiler.typesTask.typesInferrer; | 33 var typesInferrer = compiler.typesTask.typesInferrer; |
33 | 34 |
34 checkFieldTypeInClass(String className, String fieldName, type) { | 35 checkFieldTypeInClass(String className, String fieldName, type) { |
35 var cls = findElement(compiler, className); | 36 var cls = findElement(compiler, className); |
36 var element = cls.lookupLocalMember(buildSourceString(fieldName)); | 37 var element = cls.lookupLocalMember(buildSourceString(fieldName)); |
37 Expect.equals(type, | 38 Expect.equals(type, |
38 typesInferrer.getTypeOfElement(element).simplify(compiler)); | 39 typesInferrer.getTypeOfElement(element).simplify(compiler)); |
39 } | 40 } |
40 | 41 |
41 checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType); | 42 checkFieldTypeInClass('A', 'intField', compiler.typesTask.intType); |
42 checkFieldTypeInClass('A', 'giveUpField1', | 43 checkFieldTypeInClass('A', 'giveUpField1', |
43 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass')); | 44 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass')); |
44 checkFieldTypeInClass('A', 'giveUpField2', | 45 checkFieldTypeInClass('A', 'giveUpField2', |
45 compiler.typesTask.dynamicType.nonNullable()); | 46 compiler.typesTask.dynamicType.nonNullable()); |
46 checkFieldTypeInClass('A', 'fieldParameter', compiler.typesTask.intType); | 47 checkFieldTypeInClass('A', 'fieldParameter', compiler.typesTask.intType); |
| 48 })); |
47 } | 49 } |
OLD | NEW |