Skip to content

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

Open

Description

@captnCC

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?

Activity

  1. davidmorgan commented on Nov 1, 2022

    @davidmorgan
    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?

  2. self-assigned this
    on Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions