ponyc
ponyc copied to clipboard
Confusing type name on error messages with function lookup on lambda types
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.
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.
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.
- the concrete lambda class/primitive has no inherent link to the lambda interface type (which has a nice way to print)
- object literals may have multiple methods, and thus no nice way to print even an interface for it
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)