diff --git a/angel_container/lib/src/mirrors/reflector.dart b/angel_container/lib/src/mirrors/reflector.dart index 2212977f..9cf07fb1 100644 --- a/angel_container/lib/src/mirrors/reflector.dart +++ b/angel_container/lib/src/mirrors/reflector.dart @@ -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 diff --git a/angel_container/test/common.dart b/angel_container/test/common.dart index 53101422..52b8a6d2 100644 --- a/angel_container/test/common.dart +++ b/angel_container/test/common.dart @@ -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 }