`FullType`s with generic input doesn't equal concrete type
captnCC opened this issue · 1 comments
I'm trying to implement a REST API deserialisation with built_value
. Because the general pattern for Responses ist always equal, I want to use a Generic to handle this part (I know I still have to registers the builder anyway).
The type of the serializer should be taken from the wrapping generic instead of passing another FullType
with the concrete instances.
After a lot of trial and error I found the problem that causes the BuildFactory to not be found for the type.
TLDR; The hashCode
for the concrete and from a generic derived FullType
don't match.
A little sample:
fromGeneric<TSerializeable>() => FullType(BaseType<TSerializeable>, [FullType(TSerializeable)]);
final concrete = FullyType(BaseType<Concrete>, [FullType(Concrete)]);
final generic = fromGeneric<Concrete> ();
// should equal
concrete.hashCode == generic.hashCode
Is there a way to get them to equal somehow?
(Sorry for the slow response!)
Your example doesn't compile, I think; FullType(BaseType<TSerializable>,
is not valid Dart, it should be just FullType(BaseType, [FullType(TSerializable)])
.
And then the corresponding change for fromGeneric
, it should be FullType(BaseType, [FullType(TSerializable)])
.
This passes
test('hashCode matches if created via generics', () {
var concrete = FullType(List, [FullType(int)]);
var generic = fromGeneric<int>();
expect(concrete.hashCode, generic.hashCode);
});
FullType fromGeneric<T>() => FullType(List, [FullType(T)]);
so as far as I can see, this works?