Skip to content

mirrors Invoke API is unnecessary picky given our provided input API #16745

@efortuna

Description

@efortuna

To call invoke, you pass in positional arguments and named arguments.

InstanceMirror invoke(Symbol memberName, List positionalArguments, [Map<Symbol, dynamic> namedArguments])

Invoke throws an error if you call invoke on member that has no named arguments and you pass in an empty Map. Same for the positional arguments and an empty list.

The problem is if you get this info from an Invocation object, like from noSuchMethod, and you call invocationObj.namedArguments or invocationObject.positionalArguments they return empty lists if that member doesn't have any named/positional arguments.

As a result, to use invoke and noSuchMethod effectively, you have to individually determine if the invocation is a getter/setter/method/accessor and call invoke on each of those cases differently!

This defeats the purpose of noSuchMethod and invoke. So we probably just need to align our APIs so that either Invocation.namedArguments returns null instead of an empty list if that method/getter/etc doesn't take any arguments, or don't throw an error in invoke if we pass an empty list to a getter.

Metadata

Metadata

Labels

area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.closed-as-intendedClosed as the reported issue is expected behaviorlibrary-mirrors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions