ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

Poor error message for missing constructor arguments. #1676

Closed insanitybit closed 7 years ago

insanitybit commented 7 years ago
use "format"
use "files"

actor DirectoryTraverser
  be traverse(target: String val) =>
    let directory = Directory.open(target)

actor Main
  new create(env: Env) =>
    env.out.print("foo")

not enough arguments let directory = Directory.open(target)

SeanTAllen commented 7 years ago

I asked @insanitybit to open this in IRC.

If you look at Directory.open:

fun open(target: String): Directory iso^ ? =>

it takes a single argument that is a string. However, its not a constructor. The error message that results from calling on Directory the class rather than an instance of the class could be much better.

jemc commented 7 years ago

The simplest thing we could do to improve this UX is to add an "info" line to this (using ast_error_continue) to point to the definition of the function signature, to show you what arguments are expected, to demonstrate why you're not providing enough. This would be helpful in general, but would also help in this case to show you that it's trying to call the constructor.

KaroLaunonen commented 7 years ago

@jemc Can you take a look at my fix suggestion.

Error messages for too many / not enough arguments now look like:

Error:
/home/klaunonen/Develop/pony/not_enough-args/argh.pony:5:36: too many arguments
    let dirTooManyArgs = Directory(".", 1)
                                   ^
    Info:
    /home/klaunonen/Develop/pony/ponyc-klaunonen/packages/files/directory.pony:32:14: definition is here
      new create(from: FilePath) ? =>
                 ^
Error:
/home/klaunonen/Develop/pony/not_enough-args/argh.pony:6:37: not enough arguments
    let dirNotEnoughArgs = Directory.open(target)
                                    ^
    Info:
    /home/klaunonen/Develop/pony/ponyc-klaunonen/packages/files/directory.pony:32:14: definition is here
      new create(from: FilePath) ? =>
                 ^
jemc commented 7 years ago

@KaroLaunonen - Thanks, looks perfect! Want to file it as a PR?

Perelandric commented 7 years ago

@jemc If I'm not mistaken, this is resolved as of the May 17 commit https://github.com/ponylang/ponyc/commit/939cf25789c72fec3e623570cb4f8cf934fc6214

jemc commented 7 years ago

@Perelandric - yes, thanks!