NoSuchMethodError object produces confusing error messages #13471
Labels
area-library
core-a
library-core
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
This issue was originally filed by @mhausner
Assume function foo defined like this:
foo(a,{b}) => print("ha");
And a call to foo like this
foo(10,20)
This produces a NoSuchMethodError that claims that an incorrect number of arguments was passed to foo:
The VM says:
Unhandled exception:
No top-level method 'foo' with matching arguments declared.
NoSuchMethodError: incorrect number of arguments passed to method named 'foo'
Receiver: top-level
Tried calling: foo(10, 20)
Found: foo(a, b)
Dart2js says:
out.js:430: NoSuchMethodError: incorrect number of arguments passed to method named 'Symbol("foo")'
Receiver: ""
Tried calling: Symbol("foo")(10, 20)
Found: Symbol("foo")(a, b)
throw H.wrapException(new P.NoSuchMethodError(obj, new H.Symbol0($name), $ar
The error message is confusing. It says that foo was called with two arguments, and that we found a foo with two arguments, but the error is "wrong number of arguments"....
The problem is that in the "Found" call target, we can't express the actual signature of foo. The NoSuchMethodError object takes a list of names for the parameters of the function we found, but no info about positional, optional and named arguments.
NoSuchMethodError(Object receiver,
Symbol memberName,
List positionalArguments,
Map<Symbol ,dynamic> namedArguments,
[List existingArgumentNames = null]) <<<==== names of arguments of function
Instead of a list of argument names, the NoSuchMethodError object should instead take a String describing the signature of the existing function. Or it should not define that part in the public API and leave it to the implementation to handle it.
The text was updated successfully, but these errors were encountered: