| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'package:kernel/class_hierarchy.dart'; |
| 5 import 'package:kernel/core_types.dart'; |
| 4 import 'package:kernel/kernel.dart'; | 6 import 'package:kernel/kernel.dart'; |
| 5 import 'package:kernel/transformations/mixin_full_resolution.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; |
| 6 | 10 |
| 7 import 'baseline_tester.dart'; | 11 import 'baseline_tester.dart'; |
| 8 | 12 |
| 9 class StrongModeTest extends TestTarget { | 13 class StrongModeTest extends TestTarget { |
| 10 @override | 14 @override |
| 11 List<String> get extraRequiredLibraries => []; | 15 List<String> get extraRequiredLibraries => []; |
| 12 | 16 |
| 13 @override | 17 @override |
| 14 String get name => 'strong-mode-test'; | 18 String get name => 'strong-mode-test'; |
| 15 | 19 |
| 16 @override | 20 @override |
| 17 bool get strongMode => true; | 21 bool get strongMode => true; |
| 18 | 22 |
| 19 @override | 23 @override |
| 20 void transformProgram(Program program) { | 24 List<String> transformProgram(Program program) { |
| 25 List<String> errors = <String>[]; |
| 21 new MixinFullResolution().transform(program); | 26 new MixinFullResolution().transform(program); |
| 27 new TestTypeChecker( |
| 28 errors, new CoreTypes(program), new ClassHierarchy(program)) |
| 29 .checkProgram(program); |
| 30 return errors; |
| 22 } | 31 } |
| 23 } | 32 } |
| 24 | 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 |
| 25 void main() { | 61 void main() { |
| 26 runBaselineTests('strong-mode', new StrongModeTest()); | 62 runBaselineTests('strong-mode', new StrongModeTest()); |
| 27 } | 63 } |
| OLD | NEW |