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 // Test that computation of callers of an element works when two | 5 // Test that computation of callers of an element works when two |
6 // elements of the same name are being invoked in the same method. | 6 // elements of the same name are being invoked in the same method. |
7 | 7 |
8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import 'package:compiler/src/inferrer/type_graph_inferrer.dart'; | 10 import 'package:compiler/src/inferrer/type_graph_inferrer.dart'; |
| 11 import 'package:compiler/src/world.dart' show ClosedWorldRefiner; |
11 | 12 |
12 import 'compiler_helper.dart'; | 13 import 'compiler_helper.dart'; |
13 | 14 |
14 const String TEST = """ | 15 const String TEST = """ |
15 class A { | 16 class A { |
16 var field; | 17 var field; |
17 } | 18 } |
18 | 19 |
19 class B { | 20 class B { |
20 var field; | 21 var field; |
21 } | 22 } |
22 | 23 |
23 main() { | 24 main() { |
24 new A().field; | 25 new A().field; |
25 new B().field; | 26 new B().field; |
26 } | 27 } |
27 """; | 28 """; |
28 | 29 |
29 // Create our own type inferrer to avoid clearing out the internal | 30 // Create our own type inferrer to avoid clearing out the internal |
30 // data structures. | 31 // data structures. |
31 class MyInferrer extends TypeGraphInferrer { | 32 class MyInferrer extends TypeGraphInferrer { |
32 MyInferrer(compiler, commonMasks) : super(compiler, commonMasks); | 33 MyInferrer(compiler, closedWorld, closedWorldRefiner) |
| 34 : super(compiler, closedWorld, closedWorldRefiner); |
33 clear() {} | 35 clear() {} |
34 } | 36 } |
35 | 37 |
36 void main() { | 38 void main() { |
37 Uri uri = new Uri(scheme: 'source'); | 39 Uri uri = new Uri(scheme: 'source'); |
38 var compiler = compilerFor(TEST, uri, analyzeOnly: true); | 40 var compiler = compilerFor(TEST, uri, analyzeOnly: true); |
39 asyncTest(() => compiler.run(uri).then((_) { | 41 asyncTest(() => compiler.run(uri).then((_) { |
40 compiler.closeResolution(); | 42 ClosedWorldRefiner closedWorldRefiner = compiler.closeResolution(); |
41 var inferrer = | 43 var inferrer = |
42 new MyInferrer(compiler, compiler.closedWorld.commonMasks); | 44 new MyInferrer(compiler, compiler.closedWorld, closedWorldRefiner); |
43 compiler.globalInference.typesInferrerInternal = inferrer; | 45 compiler.globalInference.typesInferrerInternal = inferrer; |
44 compiler.globalInference.runGlobalTypeInference(compiler.mainFunction); | 46 compiler.globalInference.runGlobalTypeInference( |
| 47 compiler.mainFunction, compiler.closedWorld, closedWorldRefiner); |
45 var mainElement = findElement(compiler, 'main'); | 48 var mainElement = findElement(compiler, 'main'); |
46 var classA = findElement(compiler, 'A'); | 49 var classA = findElement(compiler, 'A'); |
47 var fieldA = classA.lookupLocalMember('field'); | 50 var fieldA = classA.lookupLocalMember('field'); |
48 var classB = findElement(compiler, 'B'); | 51 var classB = findElement(compiler, 'B'); |
49 var fieldB = classB.lookupLocalMember('field'); | 52 var fieldB = classB.lookupLocalMember('field'); |
50 | 53 |
51 Expect.isTrue(inferrer.getCallersOf(fieldA).contains(mainElement)); | 54 Expect.isTrue(inferrer.getCallersOf(fieldA).contains(mainElement)); |
52 Expect.isTrue(inferrer.getCallersOf(fieldB).contains(mainElement)); | 55 Expect.isTrue(inferrer.getCallersOf(fieldB).contains(mainElement)); |
53 })); | 56 })); |
54 } | 57 } |
OLD | NEW |