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

json macro throws when there is a colliding member #55696

Open
mit-mit opened this issue May 12, 2024 · 3 comments
Open

json macro throws when there is a colliding member #55696

mit-mit opened this issue May 12, 2024 · 3 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@mit-mit
Copy link
Member

mit-mit commented May 12, 2024

Repro:

@JsonCodable()
class Vehicle {
  final int wheels;
  final String description;
  Vehicle(this.wheels, this.description);
  Vehicle.fromJson(Map m) : this(2, 'foo');
}

Expected result: Just the error "Cannot generate a fromJson constructor due to this existing one."

Actual result: That error + a throw:

Invalid argument(s): [typeParameters.length: 2][typeArguments.length: 0][element: abstract interface class Map<K, V>][typeParameters: [K, V]][typeArguments: []] #0      new InterfaceTypeImpl (package:analyzer/src/dart/element/type.dart:487:7)
#1      InterfaceElementImpl.instantiate (package:analyzer/src/dart/element/element.dart:3709:18)
#2      DeclarationBuilder._resolveTypeCodeNamed (package:analyzer/src/summary2/macro_declarations.dart:519:24)
#3      DeclarationBuilder.resolveType (package:analyzer/src/summary2/macro_declarations.dart:321:16)
#4      _DeclarationPhaseIntrospector.resolve (package:analyzer/src/summary2/macro_application.dart:1130:35)
#5      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:89:22)
#6      _rootRun (dart:async/zone.dart:1399:13)
#7      _CustomZone.run (dart:async/zone.dart:1301:19)
#8      withRemoteInstanceZone (package:_macros/src/executor/remote_instance.dart:172:15)
#9      new ExternalMacroExecutorBase.<anonymous closure>.<anonymous closure> (package:_macros/src/executor/executor_base.dart:45:9)
#10     _rootRunUnary (dart:async/zone.dart:1415:13)
#11     _CustomZone.runUnary (dart:async/zone.dart:1308:19)
#12     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1217:7)
#13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#14     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#15     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#16     _StreamController._add (dart:async/stream_controller.dart:658:7)
#17     _StreamController.add (dart:async/stream_controller.dart:606:5)
#18     _SingleIsolatedMacroExecutor.start.<anonymous closure> (package:_macros/src/executor/isolated_executor.dart:64:33)
#19     _rootRunUnary (dart:async/zone.dart:1415:13)
#20     _CustomZone.runUnary (dart:async/zone.dart:1308:19)
#21     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1217:7)
#22     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365:11)
#23     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297:7)
#24     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
#25     _StreamController._add (dart:async/stream_controller.dart:658:7)
#26     _StreamController.add (dart:async/stream_controller.dart:606:5)
#27     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
@mit-mit mit-mit added P1 A high priority bug; for example, a single project is unusable or has many test failures area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. feature-macros Implementation of the macros feature labels May 12, 2024
@jakemac53 jakemac53 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. and removed area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels May 14, 2024
@bwilkerson
Copy link
Member

Any progress?

@jakemac53 jakemac53 removed their assignment May 22, 2024
@jakemac53
Copy link
Contributor

Sorry, didn't realize I was assigned here. I am pretty sure this is an analyzer error due to the missing type arguments on Map.

@jakemac53
Copy link
Contributor

jakemac53 commented May 22, 2024

Specifically, the macro is asking to resolve the type Map. Currently the analyzer will throw if you ask to resolve a type which has type parameters, but no explicit type arguments. And by resolve, I mean calling the resolve API on the DeclarationPhaseIntrospector implementation, which converts it to a "StaticType" - this roughly translates to an "InterfaceType" in the analyzer, which is what it tries to create. But that requires explicit type arguments, so something needs to add those in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-macros Implementation of the macros feature P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

3 participants