Closed kaomoneus closed 1 year ago
The documentation comment on isSubtypeOf
actually says the following:
/// Note that this method can only be invoked successfully if all the
/// supertypes of the receiver are covered by the reflector, and a
/// `TypeRelationsCapability` has been requested.
For a class/mixin that does not declare any superinterfaces explicitly (that is, we do not have an extends
clause, a with
clause, an implements
clause, or, for a mixin, an on
clause), we always have Object
as an implicitly provided superinterface. (The class Object
itself is an exception, but we don't have to worry about how that is possible, the compiler/analyzer can always give platform provided libraries a non-standard treatment if needed.)
In particular, both Base0
and Base1
have Object
as a supertype.
If you add superclassQuantifyCapability
in the constructor named MyReflection
then you do not get the run-time error.
In some situations it might be inconvenient to cover the required types because the resulting amount of generated code is so large (because you have to cover all supertypes). If that is true for your project then you could consider using types directly for the purpose of determining subtype relationships:
bool isSubtypeOf<X, Y>() => <X>[] is List<Y>;
void main() {
print(isSubtypeOf<int, num>()); // 'true'.
print(isSubtypeOf<String, num>()); // 'false'.
print(isSubtypeOf<List<List<num>>, Iterable<Object>>()); // 'true'.
}
You can create connections to mirrors of types by comparing the actual type (like X
above) to the reflectedType
of the TypeMirror
.
I'll close this issue because this is all working as intended (but we can add further comments here if needed).
Ok, thank you for explanation!
I observed following counter-intuitive behaviour, consider following code:
The reason is that
xxx.reflectable.dart
setssuperClassIndex = noCapabilityIndex
even for classes with capability but without parents. It looks like problem lays in builder_implementation.dart, _classMirrorCode. I believe that extra case tosuperclassIndex
initialization should solve this issue.