Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diag: macro diagnostic shows incorrect line number #115

Open
bqwstt opened this issue Oct 12, 2024 · 2 comments
Open

diag: macro diagnostic shows incorrect line number #115

bqwstt opened this issue Oct 12, 2024 · 2 comments

Comments

@bqwstt
Copy link

bqwstt commented Oct 12, 2024

The following snippet fails to compile, and the diagnostic references an incorrect line number for the error:

fn main() {
    macro wrapper() {
        println("I forgot to invoke this macro!");
    }

    wrapper!();
}

The error I get:

/usr/local/bin/alumina-boot --cfg threading --sysroot /usr/local/share/alumina --debug --output build/debug/macro_diag.c \
        macro_diag::main=src/main.alu
error: unexpanded macro (hint: append `!` to invoke it)
  --> src/main.alu:6:5

In this case, src/main:6:5 is not where the actual error is, but in src/main:3:9. This can be confusing, especially when other macros call each other.

fn main() {
    macro wrapper() {
        println("I forgot to invoke this macro!");
    }

    macro wrapper_wrapper() {
        wrapper!()
    }

    macro yet_another_wrapper() {
        wrapper_wrapper!()
    }

    yet_another_wrapper!();
}

produces:

/usr/local/bin/alumina-boot --cfg threading --sysroot /usr/local/share/alumina --debug --output build/debug/macro_diag.c \
        macro_diag::main=src/main.alu
error: unexpanded macro (hint: append `!` to invoke it)
  --> src/main.alu:14:5

It would be nice to either:

  • show the root line number causing the problem
  • provide context around the error (i.e., displaying a snippet of the code)
  • providing the macro name where the failure is
  • all of the above?

Compilation Info

Revision: 8a621ba34ccf041bf963b46ad25f9756d43650b8

8a621ba3 (HEAD -> master, origin/master, origin/HEAD) feat(stdlib): Test framework improvements (#114)
@tibordp
Copy link
Member

tibordp commented Oct 13, 2024

Woo, a first user of Alumina that's not me 💯

Macros being opaque for the purpose of diagnostics is somewhat intentional, as this allows programs to e.g. define custom macros that report the span of the call site instead of the macro itself (which would not be terribly useful), see for example: https://play.alumina-lang.net/?code=929c1ff2e347fad9

I think it would be useful to provide this additional context in the form of "stack trace" like it is done during monomorphization, but currently once AST is constructed, each AST node has just one (or none) source span attached.

I think diagnostics in general leaves a lot to be desired - I'll leave this issue open, but probably it'll be a while before I get to it.

@bqwstt
Copy link
Author

bqwstt commented Oct 13, 2024

That makes sense, thank you for the example.

By the way, really liking the language so far -- it combines all of the features I like from different PLs I've tried. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants