OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 import 'package:kernel/class_hierarchy.dart'; | |
5 import 'package:kernel/core_types.dart'; | |
6 import 'package:kernel/kernel.dart'; | |
7 import 'package:kernel/transformations/mixin_full_resolution.dart'; | |
8 import 'package:kernel/type_checker.dart'; | |
9 import 'package:path/path.dart' as pathlib; | |
10 | |
11 import 'baseline_tester.dart'; | |
12 | |
13 class StrongModeTest extends TestTarget { | |
14 @override | |
15 List<String> get extraRequiredLibraries => []; | |
16 | |
17 @override | |
18 String get name => 'strong-mode-test'; | |
19 | |
20 @override | |
21 bool get strongMode => true; | |
22 | |
23 @override | |
24 List<String> transformProgram(Program program) { | |
25 List<String> errors = <String>[]; | |
26 new MixinFullResolution().transform(program); | |
27 new TestTypeChecker( | |
28 errors, new CoreTypes(program), new ClassHierarchy(program)) | |
29 .checkProgram(program); | |
30 return errors; | |
31 } | |
32 } | |
33 | |
34 class TestTypeChecker extends TypeChecker { | |
35 final List<String> errors; | |
36 | |
37 TestTypeChecker(this.errors, CoreTypes coreTypes, ClassHierarchy hierarchy) | |
38 : super(coreTypes, hierarchy); | |
39 | |
40 @override | |
41 void checkAssignable(TreeNode where, DartType from, DartType to) { | |
42 if (!environment.isSubtypeOf(from, to)) { | |
43 fail(where, '$from is not a subtype of $to'); | |
44 } | |
45 } | |
46 | |
47 @override | |
48 void fail(TreeNode where, String message) { | |
49 var location = where.location; | |
50 var locationString; | |
51 if (location != null) { | |
52 var file = pathlib.basename(Uri.parse(location.file).path); | |
53 locationString = '($file:${location.line}:${location.column})'; | |
54 } else { | |
55 locationString = '(no location)'; | |
56 } | |
57 errors.add('$message $locationString'); | |
58 } | |
59 } | |
60 | |
61 void main() { | |
62 runBaselineTests('strong-mode', new StrongModeTest()); | |
63 } | |
OLD | NEW |