Skip to content

JsonCodable Causes Compilation Error When Field's Type Has Custom Json implementation #59771

Open
@mcmah309

Description

@mcmah309

JsonCodable causes a compilation issue when used with another macro introduces valid toJson and fromJson methods.

Example here: https://github.com/mcmah309/algebraic_types/blob/65044fa18988a6cadd346f88648933070d60330f/serde_test/dart/bin/dart.dart

Run command

dart run --enable-experiment=macros

Run command

kernel-service: Error: Unhandled exception:
type 'TypeDeclarationBuilderIdentifier' is not a subtype of type 'MacroExceptionImpl' in type cast
#0      DeserializerExtensions.expectRemoteInstance (package:_macros/src/executor/serialization_extensions.dart:18:21)
#1      new SerializableResponse.deserialize (package:_macros/src/executor/protocol.dart:89:34)
#2      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:53:38)
#3      _rootRun (dart:async/zone.dart:1525:13)
#4      _CustomZone.run (dart:async/zone.dart:1422:19)
#5      withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
#6      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:45:9)
#7      _rootRunUnary (dart:async/zone.dart:1546:13)
#8      _CustomZone.runUnary (dart:async/zone.dart:1429:19)
#9      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#11     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#12     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#13     _StreamController._add (dart:async/stream_controller.dart:663:7)
#14     _StreamController.add (dart:async/stream_controller.dart:618:5)
#15     _SingleIsolatedMacroExecutor.start.<anonymous closure> (package:_macros/src/executor/isolated_executor.dart:64:33)
#16     _rootRunUnary (dart:async/zone.dart:1546:13)
#17     _CustomZone.runUnary (dart:async/zone.dart:1429:19)
#18     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
#19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#22     _StreamController._add (dart:async/stream_controller.dart:663:7)
#23     _StreamController.add (dart:async/stream_controller.dart:618:5)
#24     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)

Unhandled exception:
type 'TypeDeclarationBuilderIdentifier' is not a subtype of type 'MacroExceptionImpl' in type cast
#0      DeserializerExtensions.expectRemoteInstance (package:_macros/src/executor/serialization_extensions.dart:18:21)
#1      new SerializableResponse.deserialize (package:_macros/src/executor/protocol.dart:89:34)
#2      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:53:38)
#3      _rootRun (dart:async/zone.dart:1525:13)
#4      _CustomZone.run (dart:async/zone.dart:1422:19)
#5      withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
#6      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:45:9)
#7      _rootRunUnary (dart:async/zone.dart:1546:13)
#8      _CustomZone.runUnary (dart:async/zone.dart:1429:19)
#9      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#11     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#12     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#13     _StreamController._add (dart:async/stream_controller.dart:663:7)
#14     _StreamController.add (dart:async/stream_controller.dart:618:5)
#15     _SingleIsolatedMacroExecutor.start.<anonymous closure> (package:_macros/src/executor/isolated_executor.dart:64:33)
#16     _rootRunUnary (dart:async/zone.dart:1546:13)
#17     _CustomZone.runUnary (dart:async/zone.dart:1429:19)
#18     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1329:7)
#19     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:381:11)
#20     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:312:7)
#21     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:798:19)
#22     _StreamController._add (dart:async/stream_controller.dart:663:7)
#23     _StreamController.add (dart:async/stream_controller.dart:618:5)
#24     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:194:12)

If you comment out these lines https://github.com/mcmah309/algebraic_types/blob/65044fa18988a6cadd346f88648933070d60330f/serde_test/dart/bin/dart.dart#L6-L12 the code compiles and succeeds.

Dart info:

#### General info

- Dart 3.7.0-232.0.dev (dev) (None) on "linux_x64"
- on linux / Linux 6.6.63 #1-NixOS SMP PREEMPT_DYNAMIC Fri Nov 22 14:38:37 UTC 2024
- locale is en_US.UTF-8

#### Project info

- sdk constraint: '^3.7.0-232.0.dev'
- dependencies: http, json
- dev_dependencies: lints, test
- elided dependencies: 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    cfe-feature-macrosImplement macros features in the CFElegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions