Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FullTypes with generic input doesn't equal concrete type #1189

Open
captnCC opened this issue Oct 9, 2022 · 1 comment
Open

FullTypes with generic input doesn't equal concrete type #1189

captnCC opened this issue Oct 9, 2022 · 1 comment
Assignees
Labels

Comments

@captnCC
Copy link

captnCC commented Oct 9, 2022

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?

@davidmorgan
Copy link
Collaborator

(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?

@davidmorgan davidmorgan self-assigned this Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants