schultek / dart_mappable

Improved json serialization and data classes with full support for generics, inheritance, customization and more.
https://pub.dev/packages/dart_mappable
MIT License
164 stars 23 forks source link

Nested Generics don't work with extends #212

Open BenjiFarquhar opened 4 months ago

BenjiFarquhar commented 4 months ago

This code works:

@MappableClass()
class VgnItmEst<V extends VgnItm<T>, T extends Tag> with VgnItmEstMappable<V, T> {
  final V vgnItm;

  const VgnItmEst({
    required this.vgnItm,
  });
}

@MappableClass()
abstract class VgnItm<T extends Tag> with VgnItmMappable<T> {
  final List<T>? tags;

  const VgnItm({
    this.tags,
  });
}

abstract class Tag {
  int get iconCodePoint;
  String get name;
  int get value;
}

Add an extends - causes 2 exceptions in the mapper file:

@MappableClass()
class VgnItmEst<V extends VgnItm<T>, T extends Tag> extends Entity<int> with VgnItmEstMappable<V, T> {
  final V vgnItm;

  const VgnItmEst({
    required this.vgnItm,
    super.id,
  });
}

@MappableClass()
abstract class VgnItm<T extends Tag> extends Entity<int> with VgnItmMappable<T> {
  final List<T>? tags;

  const VgnItm({
    this.tags,
    super.id,
  });
}

abstract class Tag {
  int get iconCodePoint;
  String get name;
  int get value;
}

@MappableClass()
abstract class Entity<T> with EntityMappable<T> {
  final T? id;

  const Entity({
    this.id,
  });
}

Exception 1:

abstract class VgnItmEstCopyWith<
    $R,
    $In extends VgnItmEst<V, T>,
    $Out,
    V extends VgnItm<T>,
    T extends Tag> implements EntityCopyWith<$R, $In, $Out, dynamic> {
  VgnItmCopyWith<$R, VgnItm<Tag>, V> get vgnItm;
  @override
  $R call({V? vgnItm, dynamic id});
  VgnItmEstCopyWith<$R2, $In, $Out2, V, T> $chain<$R2, $Out2>(
      Then<$Out2, $R2> t);
}

The type 'VgnItmCopyWith' is declared with 4 type parameters, but 3 type arguments were given. Try adjusting the number of type arguments to match the number of type parameters.dartwrong_number_of_type_arguments

Exception 2:

class _VgnItmEstCopyWithImpl<$R, $Out, V extends VgnItm<T>, T extends Tag>
    extends ClassCopyWithBase<$R, VgnItmEst<V, T>, $Out>
    implements VgnItmEstCopyWith<$R, VgnItmEst<V, T>, $Out, V, T> {
  _VgnItmEstCopyWithImpl(super.value, super.then, super.then2);

  @override
  late final ClassMapperBase<VgnItmEst> $mapper =
      VgnItmEstMapper.ensureInitialized();
  @override
  VgnItmCopyWith<$R, VgnItm<Tag>, V> get vgnItm =>
      $value.vgnItm.copyWith.$chain((v) => call(vgnItm: v));
  @override
  $R call({V? vgnItm, Object? id = $none}) => $apply(FieldCopyWithData(
      {if (vgnItm != null) #vgnItm: vgnItm, if (id != $none) #id: id}));
  @override
  VgnItmEst<V, T> $make(CopyWithData data) => VgnItmEst(
      vgnItm: data.get(#vgnItm, or: $value.vgnItm),
      id: data.get(#id, or: $value.id));

  @override
  VgnItmEstCopyWith<$R2, VgnItmEst<V, T>, $Out2, V, T> $chain<$R2, $Out2>(
          Then<$Out2, $R2> t) =>
      _VgnItmEstCopyWithImpl($value, $cast, t);
}

The type 'VgnItmCopyWith' is declared with 4 type parameters, but 3 type arguments were given. Try adjusting the number of type arguments to match the number of type parameters.dartwrong_number_of_type_arguments