rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.77k stars 178 forks source link

Error position for "Function not found" on operators points to first operand #835

Closed kim8823 closed 6 months ago

kim8823 commented 7 months ago

This is just a cosmetic issue and not even strictly wrong. The part of the source text that forms the function-call expression does indeed start there, but it would still be nice if the error actually pointed at the operator symbol.

Come to think about it, the wording could also be improved to say "Operator" and maybe even show the signature as infix syntax. The current message might be pretty confusing to rhai-only users that have nothing to do with embedding the engine.

- Function not found: * (map, i64)
+ Operator not found: map * i64
schungx commented 7 months ago

I suppose we can detect that the name of the function is a valid operator, and then remap the signature this way...

Let me try that out.

schungx commented 7 months ago

One thing is that certain code out there may depend on the fact that the name of the function is at the beginning of the signature...

For example, if you get an ErrorFunctionNotFound, it is not necessarily due to your function not being found... it could be a dependency function that is not found. So usually you have to check the signature before you decide that, yes, the function is not there.

I can add a new ErrorOperatorNotFound, but then it'd be a breaking change.

schungx commented 7 months ago

I have fixed the position of the error such that it now points to the operator instead.

schungx commented 6 months ago

Closing this for now. Feel free to reopen.