Skip to content

Error messages for wrong number of arguments are confusing #1458

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

Closed
DartBot opened this issue Feb 1, 2012 · 10 comments
Closed

Error messages for wrong number of arguments are confusing #1458

DartBot opened this issue Feb 1, 2012 · 10 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Feb 1, 2012

This issue was originally filed by [email protected]


This is clearly not a bug in the VM - but as a user it is a persistent source of confusion and I think that fixing this would help usability considerably.

These error messages are different for method calls, constructor calls and super constructor calls.

Here's a test program:
main() {
  C o = new C(2);
  o.m(1);
}

class Base {
  Base();
}

class C extends Base {
  C(var x): super(x); // call super construtor with wrong arg count

  m(var x) => null;
}


As written, this produces the most confusing of the messages:
$ ../xcodebuild/Release_ia32/dart t.dart
'/Users/jimhug/dartfrog/dart/frog/t.dart': Error: line 16 pos 13: super class constructor 'Base.' not found
  C(var x): super(x);
            ^

If that bug is fixed, but the original call to the constructor is changed to "C o = new C();" then the new message is:
$ ../xcodebuild/Release_ia32/dart t.dart
'/Users/jimhug/dartfrog/dart/frog/t.dart': Error: line 2 pos 9: invalid arguments passed to constructor 'C' for class 'C'
  C o = new C();
        ^
This is the most useful of the messages - but the notion of "invalid arguments" is not clear. It would be very helpful if it specified an incorrect argument count and ideally something of the form, expected 1 argument but found 0.

If that bug is fixed, but the call to m is changed to "o.m()", then the new message is:
$ ../xcodebuild/Release_ia32/dart t.dart
Unhandled exception:
NoSuchMethodException - receiver: 'Instance of 'C'' function name: 'm' arguments: []]
 0. Function: 'Object.noSuchMethod' url: 'bootstrap' line:623 col:3
 1. Function: '::main' url: '/Users/jimhug/dartfrog/dart/frog/t.dart' line:3 col:6

I see how this one is the most difficult to change given the dart spec for NoSuchMethod handling. However, I find this surprising and confusing because it feels to me like there is a method 'm' defined on 'C' - however that method is simply not capable of responding to a message with zero arguments. Again, a message that specified incorrect argument count would be helpful and one that specified "expected 1 argument but found 0" would be most helpful.

@ghost
Copy link

ghost commented Feb 1, 2012

Set owner to @sgmitrovic.
Added Accepted label.

@ghost
Copy link

ghost commented Feb 3, 2012

NoSuchMethodException is now reporting a method with the same name but different arguments.

@DartBot
Copy link
Author

DartBot commented Jun 4, 2012

This comment was originally written by [email protected]


Can I take this one?

@DartBot
Copy link
Author

DartBot commented Jun 4, 2012

This comment was originally written by [email protected]


Actually, I have already started implementing the changes, just wanted to see if anyone had any objections to that.

@iposva-google
Copy link
Contributor

Jean-Rémi, no problem if you want to take a crack at it. There were quite a few changes recently about static warnings versus runtime errors, not sure if this particular message is impacted though. If it is please make sure that your implementation matches that.


cc @gbracha.

@DartBot
Copy link
Author

DartBot commented Jul 6, 2012

This comment was originally written by [email protected]


Just want to post an update. I have been procrastinating to get this change made. My summer internship is draining me of my programming energy.

I finally got down to spending a few hours on this toonight and I "fixed" the first case

It now produces the following error message:

[default@jr Debug_ia32]$ ./dart test.dart
'file:///home/default/Google/dart-repo/dart/runtime/out/Debug_ia32/test.dart': Error: line 11 pos 13: expected 0 argument(s) but found 1
  C(var x): super(x); // call super construtor with wrong arg count
            ^

@ghost
Copy link

ghost commented Aug 29, 2012

This looks good enough for me.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Aug 29, 2012

This comment was originally written by [email protected]


Just to clarify. Since I still haven't taken the time to adress all three sub-issues, I did not yet go through the process of creating a pull request or whichever other way external developers may offer patches.

I am not 100% sure what "this" refers too, just wanted to try and makes things as clear as possible.

@ghost
Copy link

ghost commented Aug 29, 2012

case 1:
'file:///sources/chinstrap/dart/Test.dart': Error: line 11 pos 13: invalid arguments passed to super class constructor 'Base.': 1 passed, 0 expected

case 2:
'file:///sources/chinstrap/dart/Test.dart': Error: line 2 pos 14: invalid arguments passed to constructor 'C' for class 'C': 0 passed, 1 expected

case 3:
NoSuchMethod printing is tracked by issue #546.

@DartBot
Copy link
Author

DartBot commented Mar 21, 2013

This comment was originally written by [email protected]


It looks like the updated check can behave incorrectly if a mixin presents: https://code.google.com/p/dart/issues/detail?id=9339

@DartBot DartBot added Type-Enhancement P1 A high priority bug; for example, a single project is unusable or has many test failures area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Mar 21, 2013
@DartBot DartBot assigned ghost Mar 21, 2013
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed type-enhancement labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants