Skip to content

"Requesting mirror on un-marked class" while using isSubtypeOf()` #69

Closed

Description

@stevenroose

I have a setup like this:

@MyReflector()
class A {}

class B extends A {}

@MyReflector()
class C extends B {}

@MyReflector()
class D extends C {}

class MyReflector extends Reflectable {
  const MyReflector() : super(declarationsCapability, typeRelationsCapability);
}

Note that the classes or not really declared like this, they are in different libraries, but the tree in important and what classes are reflected on.
Now, when I have a class mirror on D and one on A and I try to do dMirror.isSubtypeOf(aMirror), I get this error:

  Failed to load "test/all_tests_web.dart": Requesting mirror on un-marked class, superclass of 'C'
  all_tests_web.dart.browser_test.dart.js 3187:17   dart.wrapException
  all_tests_web.dart.browser_test.dart.js 37186:19  NonGenericClassMirrorImpl.dart.ClassMirrorBase.get$superclass
  all_tests_web.dart.browser_test.dart.js 37163:18  NonGenericClassMirrorImpl.dart.ClassMirrorBase._isSubtypeOf$1
  all_tests_web.dart.browser_test.dart.js 37168:35  NonGenericClassMirrorImpl.dart.ClassMirrorBase._isSubtypeOf$1
  all_tests_web.dart.browser_test.dart.js 37157:21  NonGenericClassMirrorImpl.dart.ClassMirrorBase.isSubtypeOf$1
  all_tests_web.dart.browser_test.dart.js 33441:28  FactoryRegistry.dart.FactoryRegistry._isRegistrableDeclaration$1
  all_tests_web.dart.browser_test.dart.js 3507:14   anonymous.eval
  all_tests_web.dart.browser_test.dart.js 9072:24   WhereIterator.dart.WhereIterator._f$1
  all_tests_web.dart.browser_test.dart.js 9064:20   WhereIterator.dart.WhereIterator.moveNext$0
  all_tests_web.dart.browser_test.dart.js 15398:47  WhereIterable.dart.Iterable.forEach$1

This error only occurs in transformed mode.

I noticed that, in the VM, the class mirror instances had this String representation
ClassMirrorImpl('ClassMirror on 'ClassName''),
while in transformed mode, they are
NonGenericClassMirrorImpl(library.namespace.to.class.ClassName).

Note the use of the qualified name in transformed mode. This is probably not a problem, but it would be nice to have a more streamlined idea of when the class name is used and when the qualified name.

This issue is probably due to the fact that isSubtypeOf works recursively over the inheritance tree and when a class is in the tree that is not reflected on, it fails.

I just tried by adding a SuperclassQuantifyCapability to my reflector and it works. But I think the TypeRelationsCapability should work without having reflection over all superclasses.

Activity

  1. stevenroose commented on Jan 31, 2016

    @stevenroose
    Author

    It seems that after adding SuperclassQuantifyCapability, isSubtypeOf does no longer throw, but I seems to always return false.

  2. eernstg commented on Feb 1, 2016

    @eernstg
    Collaborator

    In fact, isSubtypeOf needs to traverse the supertype graph (including the superclass chain), and it is unable to respond with either true nor false when some types in that graph are not defined (that is, no support for them has been requested) and no evidence is found for a subtype relationship. It would be possible to return true when evidence is found, even in the cases where some types are not defined, but this would still make subtyping queries quite unsafe in a setting where just a part of the subtype graph is supported.

    We need to consider whether we want to extend the semantics to tolerate some undefined types, but it will not be possible to return false when only a part of the graph is available, so there is no way it could be made safe.

    Can't you use SubtypeQuantifyCapability to ensure that you get a complete graph in the first place?

    If you have a case where you get false but should have had true then it would be very useful if you extract a minimal example---that would be a clear bug.

  3. stevenroose commented on Feb 1, 2016

    @stevenroose
    Author

    Bumped into #72 trying to resolve this.

    In fact, this issue can be closed when isSubtypeOf is documented with a mention of the fact that all intermediary classes should have reflection support as well.

  4. eernstg commented on Feb 11, 2016

    @eernstg
    Collaborator

    https://codereview.chromium.org/1695453002/ adds documentation to many mirror methods, including the fact that isSubtypeOf and isAssignableTo requires coverage for all classes traversed by those algorithms. Issue #76 describes the underlying problem (that isSubtypeOf and isAssignableTo are expensive in terms of class coverage), so further developments will be covered there (if anybody gets a good enough idea about how to do it ;-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions