Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1094)

Unified Diff: test/baseline_strong_mode_test.dart

Issue 2465893002: Add strong mode type checking pass. (Closed)
Patch Set: Merge with master and remove visitBlockExpression Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/baseline_spec_mode_test.dart ('k') | test/baseline_tester.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/baseline_strong_mode_test.dart
diff --git a/test/baseline_strong_mode_test.dart b/test/baseline_strong_mode_test.dart
index fa8626911fe3713fab29ee970c4d8bfe1c6ce8ac..51d2a7c032e49f1b35cb1548a97e34d8ad16328f 100644
--- a/test/baseline_strong_mode_test.dart
+++ b/test/baseline_strong_mode_test.dart
@@ -1,8 +1,12 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'package:kernel/class_hierarchy.dart';
+import 'package:kernel/core_types.dart';
import 'package:kernel/kernel.dart';
import 'package:kernel/transformations/mixin_full_resolution.dart';
+import 'package:kernel/type_checker.dart';
+import 'package:path/path.dart' as pathlib;
import 'baseline_tester.dart';
@@ -17,8 +21,40 @@ class StrongModeTest extends TestTarget {
bool get strongMode => true;
@override
- void transformProgram(Program program) {
+ List<String> transformProgram(Program program) {
+ List<String> errors = <String>[];
new MixinFullResolution().transform(program);
+ new TestTypeChecker(
+ errors, new CoreTypes(program), new ClassHierarchy(program))
+ .checkProgram(program);
+ return errors;
+ }
+}
+
+class TestTypeChecker extends TypeChecker {
+ final List<String> errors;
+
+ TestTypeChecker(this.errors, CoreTypes coreTypes, ClassHierarchy hierarchy)
+ : super(coreTypes, hierarchy);
+
+ @override
+ void checkAssignable(TreeNode where, DartType from, DartType to) {
+ if (!environment.isSubtypeOf(from, to)) {
+ fail(where, '$from is not a subtype of $to');
+ }
+ }
+
+ @override
+ void fail(TreeNode where, String message) {
+ var location = where.location;
+ var locationString;
+ if (location != null) {
+ var file = pathlib.basename(Uri.parse(location.file).path);
+ locationString = '($file:${location.line}:${location.column})';
+ } else {
+ locationString = '(no location)';
+ }
+ errors.add('$message $locationString');
}
}
« no previous file with comments | « test/baseline_spec_mode_test.dart ('k') | test/baseline_tester.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698