From 51d13c8a45f3fb28deb7d5bbd9adedcdff3a1649 Mon Sep 17 00:00:00 2001 From: "karlklose@google.com" Date: Tue, 18 Feb 2014 14:12:42 +0000 Subject: [PATCH] Use the dart2js type system for isSubtypeOf and isSubclassOf. R=johnniwinther@google.com BUG= http://dartbug.com/16737 Review URL: https://codereview.chromium.org//167003004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32741 260f80e4-7a28-3924-810f-c04153c831b5 --- .../mirrors/dart2js_type_mirrors.dart | 31 ++++++++++--------- tests/compiler/dart2js/dart2js.status | 2 -- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart index 3f5bfddffac..2145f925335 100644 --- a/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart +++ b/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_type_mirrors.dart @@ -4,10 +4,6 @@ part of dart2js.mirrors; -//------------------------------------------------------------------------------ -// Types -//------------------------------------------------------------------------------ - abstract class ClassMirrorMixin implements ClassSourceMirror { bool get hasReflectedType => false; Type get reflectedType { @@ -55,11 +51,19 @@ abstract class Dart2JsTypeMirror bool get isDynamic => false; bool isSubtypeOf(TypeMirror other) { - return mirrorSystem.compiler.types.isSubtype(this._type, other._type); + if (other is Dart2JsTypeMirror) { + return mirrorSystem.compiler.types.isSubtype(this._type, other._type); + } else { + throw new ArgumentError(other); + } } bool isAssignableTo(TypeMirror other) { - return mirrorSystem.compiler.types.isAssignable(this._type, other._type); + if (other is Dart2JsTypeMirror) { + return mirrorSystem.compiler.types.isAssignable(this._type, other._type); + } else { + throw new ArgumentError(other); + } } String toString() => _type.toString(); @@ -235,15 +239,14 @@ class Dart2JsClassDeclarationMirror : super(system, type); bool isSubclassOf(ClassMirror other) { - if (other is! ClassMirror) throw new ArgumentError(other); - ClassMirror otherDeclaration = other.originalDeclaration; - ClassMirror c = this; - while (c != null) { - c = c.originalDeclaration; - if (c == otherDeclaration) return true; - c = c.superclass; + if (other is Dart2JsFunctionTypeMirror) { + return false; + } else if (other is Dart2JsClassDeclarationMirror) { + Dart2JsClassDeclarationMirror otherDeclaration = + other.originalDeclaration; + return _element.isSubclassOf(otherDeclaration._element); } - return false; + throw new ArgumentError(other); } String toString() => 'Mirror on class ${_type.name}'; diff --git a/tests/compiler/dart2js/dart2js.status b/tests/compiler/dart2js/dart2js.status index 77a9b9dc50e..a900d13608f 100644 --- a/tests/compiler/dart2js/dart2js.status +++ b/tests/compiler/dart2js/dart2js.status @@ -13,8 +13,6 @@ simple_inferrer_const_closure_test: Fail # Issue 16507 simple_inferrer_const_closure2_test: Fail # Issue 16507 simple_inferrer_global_field_closure_test: Fail # Issue 16507 -mirrors/relation_subclass_test: Fail # Issue 16737 - [ $mode == debug ] mirror_final_field_inferrer2_test: Crash, Pass, Slow # dartbug.com/15581