Amber icon indicating copy to clipboard operation
Amber copied to clipboard

fix(failed): show function

Open Mte90 opened this issue 1 year ago • 4 comments

On my daily check if I can resolve some bugs in Amber I tried with https://github.com/amber-lang/amber/issues/210

I am not sure about meta.get_index() - 4 to get the function with the issue.

Using the amberr code:

import * from "std/text"

// Output
// 123

main {
    echo parse("123")
}

The meta is:

Context { index: 15, expr: [Tok[import 1:1], Tok[* 1:8], Tok[from 1:10], Tok["std/text" 1:15], Tok[// Output
 3:1], Tok[<new_line> 3:10], Tok[// 123
 4:1], Tok[<new_line> 4:7], Tok[main 6:1], Tok[<symbol: { > 6:6], Tok[echo 7:5], Tok[parse 7:10], Tok[<symbol: ( > 7:15], Tok["123" 7:16], Tok[<symbol: ) > 7:21], Tok[<symbol: } > 8:1]]

REDACTED

So I think that the actual index is always the next symbol where it should be the failed, in this case a }, followed by the closing parenthesis of the function, the parameters, the open parenthesis and finally the function name. Right now amber doesn't share in the context what is the function or the line is processing, but in this way with - 4 we start from the end that it is more easy to be right so we can ignore the echo token.

Anyway I am not so skilled in the internals but let me know if needs some changes internally before to be able to close that ticket.

Mte90 avatar Nov 12 '24 09:11 Mte90

One way we could solve this is by including an fun_name: Option<string> in the struct of this syntax module and let the function invocation module set the function name. Then if fun_name has Some we can print the alternative error message.

If this sounds convoluted, I'll open my PR tomorrow to show what I mean

Ph0enixKM avatar Nov 14 '24 23:11 Ph0enixKM

You know better than anyone else so I think that your proposal is good. The purpose of the PR was to close the issue with adding the error message that it was missing (yet).

Mte90 avatar Nov 14 '24 23:11 Mte90

I'll try to get my hands on this pull request in a few days

Ph0enixKM avatar Dec 25 '24 11:12 Ph0enixKM

@Ph0enixKM can you check this PR now that the new translation layer was added?

Mte90 avatar Apr 10 '25 09:04 Mte90

I've improved on this error (it didn't highlight the function at all)

Screenshot 2025-07-09 at 13 17 02

Ph0enixKM avatar Jul 09 '25 11:07 Ph0enixKM

Replaced by https://github.com/amber-lang/amber/pull/769

Mte90 avatar Sep 22 '25 09:09 Mte90