Fixed a bug where _ReflectedTypeInstance.isAssignableTo
always failed.
This commit is contained in:
parent
5f79ec14e5
commit
271db26179
2 changed files with 29 additions and 2 deletions
|
@ -71,7 +71,13 @@ class _ReflectedTypeMirror extends ReflectedType {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isAssignableTo(ReflectedType other) {
|
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
|
@override
|
||||||
|
@ -136,7 +142,13 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool isAssignableTo(ReflectedType other) {
|
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
|
@override
|
||||||
|
|
|
@ -69,6 +69,17 @@ void testReflector(Reflector reflector) {
|
||||||
expect(instance.name, 'Charizard');
|
expect(instance.name, 'Charizard');
|
||||||
expect(instance.type, PokemonType.fire);
|
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 {
|
class LowerPokemon {
|
||||||
|
@ -93,4 +104,8 @@ class Pokemon {
|
||||||
String toString() => 'NAME: $name, TYPE: $type';
|
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 }
|
enum PokemonType { water, fire, grass, ice, poison, flying }
|
||||||
|
|
Loading…
Reference in a new issue