Fixed a bug where _ReflectedTypeInstance.isAssignableTo always failed.

This commit is contained in:
Tobe O 2018-08-21 10:53:37 -04:00
parent 5f79ec14e5
commit 271db26179
2 changed files with 29 additions and 2 deletions

View file

@ -71,7 +71,13 @@ class _ReflectedTypeMirror extends ReflectedType {
@override
bool isAssignableTo(ReflectedType other) {
return other is _ReflectedTypeMirror && mirror.isAssignableTo(other.mirror);
if (other is _ReflectedClassMirror) {
return mirror.isAssignableTo(other.mirror);
} else if (other is _ReflectedTypeMirror) {
return mirror.isAssignableTo(other.mirror);
} else {
return false;
}
}
@override
@ -136,7 +142,13 @@ class _ReflectedClassMirror extends ReflectedClass {
@override
bool isAssignableTo(ReflectedType other) {
return other is _ReflectedTypeMirror && mirror.isAssignableTo(other.mirror);
if (other is _ReflectedClassMirror) {
return mirror.isAssignableTo(other.mirror);
} else if (other is _ReflectedTypeMirror) {
return mirror.isAssignableTo(other.mirror);
} else {
return false;
}
}
@override

View file

@ -69,6 +69,17 @@ void testReflector(Reflector reflector) {
expect(instance.name, 'Charizard');
expect(instance.type, PokemonType.fire);
});
test('isAssignableTo', () {
var pokemonType = container.reflector.reflectType(Pokemon);
var kantoPokemonType = container.reflector.reflectType(KantoPokemon);
expect(kantoPokemonType.isAssignableTo(pokemonType), true);
expect(
kantoPokemonType
.isAssignableTo(container.reflector.reflectType(String)),
false);
});
}
class LowerPokemon {
@ -93,4 +104,8 @@ class Pokemon {
String toString() => 'NAME: $name, TYPE: $type';
}
class KantoPokemon extends Pokemon {
KantoPokemon(String name, PokemonType type) : super(name, type);
}
enum PokemonType { water, fire, grass, ice, poison, flying }