You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FullTypes with generic input doesn't equal concrete type #1189
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
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);
});
FullTypefromGeneric<T>() =>FullType(List, [FullType(T)]);
Activity
davidmorgan commentedon Nov 1, 2022
(Sorry for the slow response!)
Your example doesn't compile, I think;
FullType(BaseType<TSerializable>,is not valid Dart, it should be justFullType(BaseType, [FullType(TSerializable)]).And then the corresponding change for
fromGeneric, it should beFullType(BaseType, [FullType(TSerializable)]).This passes
so as far as I can see, this works?