Skip to content

Macro. JsonSerializable generates invalid code. #55005

@scheglov

Description

@scheglov

When I run tests for language/macros/json/json_serializable_diagnostics_test

One of the classes produces:

augment class TypeDefToFunctionTypeField {
  @prefix0.FromJson()
  external TypeDefToFunctionTypeField.fromJson(prefix1.Map<prefix1.String, prefix1.Object?> json);
  @prefix0.ToJson()
  external prefix1.Map<prefix1.String, prefix1.Object?> toJson();
  augment TypeDefToFunctionTypeField.fromJson(prefix1.Map<prefix1.String, prefix1.Object?> json, )  : this.x = <Unable to deserialize type VoidFunc>;
  augment prefix1.Map<prefix1.String, prefix1.Object?> toJson() {
    var json = <prefix1.String, prefix1.Object?>{};
    json['x'] = <Unable to serialize type VoidFunc>;
    return json;
  }
}

See <Unable to deserialize type VoidFunc> and <Unable to serialize type VoidFunc>?

This causes

- Unexpected error at tests/language/macros/json/json_serializable_diagnostics_test.macro.dart line 11, column 103, length 44: COMPILE_TIME_ERROR.EXPECTED_ONE_LIST_TYPE_ARGUMENTS

- Unexpected error at tests/language/macros/json/json_serializable_diagnostics_test.macro.dart line 11, column 103, length 44: COMPILE_TIME_ERROR.FIELD_INITIALIZER_NOT_ASSIGNABLE

- Unexpected error at tests/language/macros/json/json_serializable_diagnostics_test.macro.dart line 11, column 104, length 6: COMPILE_TIME_ERROR.NON_TYPE_AS_TYPE_ARGUMENT
<cut>

As a result, there is no way for this test to pass.

@jakemac53

Metadata

Metadata

Assignees

Labels

area-testCross-cutting test issues (use area- labels for specific failures; not used for package:test).

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions