-
Notifications
You must be signed in to change notification settings - Fork 1.7k
mirrors Invoke API is unnecessary picky given our provided input API #16745
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
Comments
Set owner to @rmacnak-google. |
"Invoke throws an error if you call invoke on member that has no named arguments and you pass in an empty Map." I do not see this behavior. import 'dart:mirrors'; class C { main() { prints an instance mirror on 3 and does not throw an exception. Can you provide an example that breaks? "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!" It sounds like you should be using InstanceMirror.delegate, which handles this for you. (It would be nice if Dart didn't distinguish between four/five kinds of invocation, but it is too late to change that.) Added NeedsInfo label. |
The error is easily reproduced if you change foo to be anything other than a method: import 'dart:mirrors'; class C { main() { results in: NoSuchMethodError : method not found: 'foo' Added Triaged label. |
It looks like you're running a VM from before Issue #8 was fixed. You should see Unhandled exception: NoSuchMethodError : method not found: 'call' which is what you would see if you wrote 'new C().get(3)' |
re comment 4: should say new C().foo(3) |
Yeah, sorry I my $dart was older than my checkout. class C { main() { $ xcodebuild/ReleaseIA32/dart-sdk/bin/dart foo.dart NoSuchMethodError : method not found: 'call' (note In my first example I incorrectly still was passing in a 3 in the argument instead of an empty list) |
Okay, this is correct behavior. Did you want this return 3? That wouldn't be Dart. |
This comment was originally written by @seaneagan The problem with delegate though is there is no easy way to create Invocations, which is issue #14776. |
Invocations of regular methods, getters, setters, and constructors are distinct in Dart. Added AsDesigned label. |
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.
The text was updated successfully, but these errors were encountered: