Skip to content
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

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

Open
mcmah309 opened this issue Dec 20, 2024 · 1 comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-macros Implement macros features in the CFE triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@mcmah309
Copy link

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
@dart-github-bot
Copy link
Collaborator

Summary: JsonCodable causes compilation errors when used with a macro that defines toJson/fromJson. A type casting error in the macro executor is reported.

@dart-github-bot dart-github-bot added area-front-end Use area-front-end for front end / CFE / kernel format related issues. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Dec 20, 2024
@johnniwinther johnniwinther added the cfe-feature-macros Implement macros features in the CFE label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-macros Implement macros features in the CFE triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants