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.7k stars 410 forks source link

Confusing type name on error messages with function lookup on lambda types #4015

Open ergl opened 2 years ago

ergl commented 2 years ago

The following code fails to compile, as expected:

actor Main
  new create(env: Env) =>
    let f = {() => None}
    f.string()

However, the error message says:

Error:
[main.pony:4:6](): couldn't find 'string' in '$1$0'
    f.string()
     ^

Internally to the compiler (I believe) we don't have a proper name for lambdas, so it's not clear what would be the appropriate type to put in the error message.

The piece of code responsible for this is lookup_nominal inside lookup.c.

The above happens for explicit lambdas, object literals and partial application.

SeanTAllen commented 2 years ago

It should be possible to know that we have a "lambda type thing" at the point of the error and change the message to "couldn't find 'string' in 'lambda f'" or something like that.

jemc commented 2 years ago

I mentioned in the sync: It's easy to hide the dollar sign name, but it's more tricky to find something useful to put there for the general case.

jemc commented 2 years ago

It may be best to just to list the methods available on the type:

Error:
[main.pony:4:6](): couldn't find 'string' in (anonymous type)
    f.string()
     ^
[main.pony:4:6](): it has a method named `apply`
    let f = {() => None}
             ^

(note that for object literals it may be multiple methods)