Skip to content

ObjectMirror.invoke ignores typeArguments #33594

Closed
@thosakwe

Description

@thosakwe
  • Dart SDK Version: 2.0.0-dev.64.1
  • Mac OSX Sierra
  • Browser: N/A

I'm updating the package json_god to work with Dart 2; it's a dart:mirrors-based reflection solution. The actual functionality works, but for the fact that Dart 2's generics are reified, and so to work with typed collections, I need to somehow attach type information to objects.

The solution I am attempting is to reflectively call List.cast with the necessary type argument; however, the ObjectMirror.delegate method forwards to ObjectMirror.invoke, which doesn't use the type arguments. Thus, the type arguments are ignored, and items like List<String> remain List<dynamic>.


My code:

logger.info('Casting list elements to ${typeArguments[0].reflectedType}');
var inv = new Invocation.genericMethod(#cast,
   [typeArguments[0].reflectedType], []);
logger.info('INVOCATION OF ${inv.memberName} with type args: ${inv
    .typeArguments}');
var output = reflect(it.toList()).delegate(inv);
logger.info('Casted list type: ${output.runtimeType}');

The current output:

[INFO] json_god: Casting list elements to String
[INFO] json_god: INVOCATION OF Symbol("cast") with type args: [String]
[INFO] json_god: About to deserialize es2015 to a String
[INFO] json_god: Value es2015 is a primitive
[INFO] json_god: About to deserialize stage-0 to a String
[INFO] json_god: Value stage-0 is a primitive
[INFO] json_god: Casted list type: CastList<dynamic, dynamic>

It's evident that that the type arguments are not actually being applied at all. I can't think of any possible workaround for this, unfortunately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.closed-not-plannedClosed as we don't intend to take action on the reported issuelibrary-mirrors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions