Skip to content

genericArgumentFactories fails on new versions: UnimplementedError: (TypeParameterTypeImpl) #1070

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

Closed
fzyzcjy opened this issue Dec 17, 2021 · 2 comments

Comments

@fzyzcjy
Copy link
Contributor

fzyzcjy commented Dec 17, 2021

Hi thanks for the lib! It seems that the following code fails on new generators. Old generators seem to work well.

The following code

@JsonSerializable(genericArgumentFactories: true)
class One<Meta> {
  Two<Meta>? two;

  One();

  factory One.fromJson(Map<String, dynamic> json, Meta Function(Object? json) fromJsonMeta) =>
      _$OneFromJson(json, fromJsonMeta);

  Map<String, dynamic> toJson(Object? Function(Meta value) toJsonMeta) => _$OneToJson(this, toJsonMeta);
}

@JsonSerializable(genericArgumentFactories: true)
class Two<Meta> {
  final Meta meta;

  const Two({required this.meta});

  factory Two.fromJson(Map<String, dynamic> json, Meta Function(Object? json) fromJsonMeta) =>
      _TwoFromJson(json, fromJsonMeta);

  Map<String, dynamic> toJson(Object? Function(Meta value) toJsonMeta) => _$TwoToJson(this, toJsonMeta);
}

generates error:

[INFO] Watch:------------------------------------------------------------------------

[INFO] Watch:Starting Build

[INFO] Build:Updating asset graph...
[INFO] Build:Updating asset graph completed, took 0ms

[INFO] Build:Running build...
[FINE] json_serializable:json_serializable on lib/components/history_dialog.dart:Running JsonSerializableGenerator - 1 of 2
[FINE] json_serializable:json_serializable on lib/components/history_dialog.dart:Running JsonLiteralGenerator - 2 of 2
[FINE] json_serializable:json_serializable on lib/utils/history_store.dart:Running JsonSerializableGenerator - 1 of 2
[SEVERE] json_serializable:json_serializable on lib/utils/history_store.dart:

UnimplementedError: (TypeParameterTypeImpl) Meta
package:json_serializable/src/utils.dart 208:3                      typeToCode
dart:_internal                                                      ListIterable.join
package:json_serializable/src/utils.dart 204:48                     typeToCode
package:json_serializable/src/type_helpers/json_helper.dart 133:17  JsonHelper.deserialize
package:json_serializable/src/type_helper_ctx.dart 68:29            TypeHelperCtx.deserialize.<fn>
dart:core                                                           Iterable.firstWhere
package:json_serializable/src/type_helper_ctx.dart 88:46            TypeHelperCtx._run
package:json_serializable/src/type_helper_ctx.dart 65:19            TypeHelperCtx.deserialize
package:json_serializable/src/decode_helper.dart 208:10             DecodeHelper._deserializeForField.deserialize
package:json_serializable/src/decode_helper.dart 230:17             DecodeHelper._deserializeForField
package:json_serializable/src/decode_helper.dart 56:9               DecodeHelper.createFactory.deserializeFun
package:json_serializable/src/decode_helper.dart 137:19             DecodeHelper.createFactory
package:json_serializable/src/generator_helper.dart 85:28           GeneratorHelper.generate
dart:_internal                                                      WhereIterator.moveNext
package:json_serializable/src/json_part_builder.dart 64:27          _UnifiedGenerator.generate
package:source_gen/src/builder.dart 326:23                          _generate

[FINE] lombok_generator:lombok on lib/components/history_dialog.dart:Running StoreGenerator
[FINE] lombok_generator:lombok on lib/utils/history_store.dart:Running StoreGenerator
[FINE] mobx_codegen:mobx_generator on lib/components/history_dialog.dart:Running StoreGenerator
[FINE] mobx_codegen:mobx_generator on lib/utils/history_store.dart:Running StoreGenerator
[INFO] Build:Running build completed, took 324ms

[INFO] Build:Caching finalized dependency graph...
[INFO] Build:Caching finalized dependency graph completed, took 67ms

[SEVERE] Build:
Failed after 394ms

@fzyzcjy fzyzcjy changed the title genericArgumentFactories fails on new versions genericArgumentFactories fails on new versions: UnimplementedError: (TypeParameterTypeImpl) Dec 17, 2021
@kevmoo
Copy link
Collaborator

kevmoo commented Dec 17, 2021

I just landed a fix here - #1047

Are you running the latest version? pub upgrade?

@kevmoo kevmoo closed this as completed Dec 17, 2021
@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Dec 17, 2021

@kevmoo Aha it is really "just" now ;) I will upgrade and rerun it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants