Skip to content

Error messages for wrong number of arguments are confusing #1458

Closed
@DartBot

Description

@DartBot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failuresarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions