asteroid-lang / asteroid

Asteroid is a modern, multi-paradigm programming language that supports first-class patterns.
https://asteroid-lang.org
MIT License
40 stars 10 forks source link

Locational error reporting #142

Open olwmc opened 2 years ago

olwmc commented 2 years ago

Consider the program:

function foo 
    with x:%integer do
        return 1.
    end

foo "string!".

Running this would return the error Error: <path>: 2: none of the function bodies unified with actual parameters

A nicer way of displaying errors would be something like this:

Error: <path>: 2: none of the function bodies unified with actual parameters

foo "string!".
^ 
lutzhamel commented 2 years ago

Yes! Actually even better,

Error: <path>: 2: none of the function bodies unified with actual parameters

foo "string!".
 .....^

where it points to the offending token or structure.

I really don't like that error message, only folks who know about our semantics can understand that message. What would be a could general error message to post here? Something like,

Error: <path>: 2: actual argument not recognized.

foo "string!".
.....^

Any other suggestions?

olwmc commented 2 years ago

I think that works well! While writing this issue I was thinking the same thing. I'll add it to #126

lutzhamel commented 1 year ago

in 1.1.4 the generated error message reads

lutz$ asteroid loc.ast
traceback (most recent call last):
loc.ast: 1: calling <toplevel>
loc.ast: 6: calling foo
error: loc.ast: 2: actual argument 'string!' not recognized by function 'foo'
lutz$ 

which is an improvement.

However, because recognizing an actual argument is pattern matching and therefore computation the error message is pointing into the function code rather than to the call site. Should we fix that?