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 final fields in @MirrorsUsed are still inferred. | 5 // Test that final fields in @MirrorsUsed are still inferred. |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
9 import 'memory_compiler.dart' show runCompiler; | 9 import 'memory_compiler.dart' show runCompiler; |
10 import 'compiler_helper.dart' show findElement; | 10 import 'compiler_helper.dart' show findElement; |
11 | 11 |
12 const MEMORY_SOURCE_FILES = const <String, String>{ | 12 const MEMORY_SOURCE_FILES = const <String, String>{ |
13 'main.dart': """ | 13 'main.dart': """ |
14 @MirrorsUsed(targets: 'Super') | 14 @MirrorsUsed(targets: 'Super') |
15 import 'dart:mirrors'; | 15 import 'dart:mirrors'; |
16 import 'lib.dart'; | 16 import 'lib.dart'; |
17 | 17 |
18 | 18 |
19 class Subclass extends Super { | 19 class Subclass extends Super { |
20 int _private; | 20 int _private; |
21 | 21 |
22 int magic() => _private++; | 22 int magic() => _private++; |
23 } | 23 } |
24 | 24 |
25 main() { | 25 main() { |
26 var objects = [new Super(), new Subclass()]; | 26 var objects = [new Super(), new Subclass()]; |
| 27 reflect(objects[0]); // Trigger mirror usage. |
27 } | 28 } |
28 """, | 29 """, |
29 'lib.dart': """ | 30 'lib.dart': """ |
30 class Super { | 31 class Super { |
31 int _private; | 32 int _private; |
32 | 33 |
33 int magic() => _private++; | 34 int magic() => _private++; |
34 } | 35 } |
35 """ | 36 """ |
36 }; | 37 }; |
37 | 38 |
38 void main() { | 39 void main() { |
39 asyncTest(() async { | 40 asyncTest(() async { |
40 var result = await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); | 41 var result = await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES); |
41 var compiler = result.compiler; | 42 var compiler = result.compiler; |
42 | 43 |
43 dynamic superclass = | 44 dynamic superclass = |
44 findElement(compiler, 'Super', Uri.parse('memory:lib.dart')); | 45 findElement(compiler, 'Super', Uri.parse('memory:lib.dart')); |
45 dynamic subclass = findElement(compiler, 'Subclass'); | 46 dynamic subclass = findElement(compiler, 'Subclass'); |
46 var oracle = compiler.backend.mirrorsData.isMemberAccessibleByReflection; | 47 var oracle = compiler.backend.mirrorsData.isMemberAccessibleByReflection; |
47 print(superclass.lookupMember('_private')); | 48 print(superclass.lookupMember('_private')); |
48 Expect.isTrue(oracle(superclass.lookupMember('_private'))); | 49 Expect.isTrue(oracle(superclass.lookupMember('_private'))); |
49 Expect.isFalse(oracle(subclass.lookupMember('_private'))); | 50 Expect.isFalse(oracle(subclass.lookupMember('_private'))); |
50 }); | 51 }); |
51 } | 52 } |
OLD | NEW |