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

Location information is lost after macro expansion #6013

Closed
asterite opened this issue Sep 12, 2024 · 0 comments · Fixed by #7333
Closed

Location information is lost after macro expansion #6013

asterite opened this issue Sep 12, 2024 · 0 comments · Fixed by #7333
Labels
bug Something isn't working

Comments

@asterite
Copy link
Collaborator

asterite commented Sep 12, 2024

Aim

Given this code:

use std::meta::unquote;

fn main() {
    comptime
    {
        let q = quote { let _x: i32 = "hello"; };
        unquote!(q);
    }
}

We get this error:

error: Expected type i32, found type str<5>
   ┌─ src/main.nr:92:9
   │
92 │         unquote!(q);
   │         -----------

Like that, it's impossible to understand how to fix the error.

Expected Behavior

Ideally the error points at exactly the "source location" of the error. I'm not sure how we can do that. But for example consider macros in Crystal:

macro my_macro(name)
    {{name}} = 1
    {{name}}.length()
end

my_macro(x)

When we call my_macro that generates this code:

name = 1
name.length()

The error Crystal gives is this:

There was a problem expanding macro 'my_macro'

Code in foo.cr:6:1

 6 | my_macro(x)
     ^
Called macro defined in foo.cr:1:1

 1 | macro my_macro(name)

Which expanded to:

 > 1 | x = 1
 > 2 | x.length()
         ^-----
Error: undefined method 'length' for Int32

The way Crystal does this is by associating the expanded macro location to a virtual location (and storing the virtual source). Then when an error happens in a virtual location its get the virtual source, shows it and shows the error.

I don't know if we could do the same, but it's just an idea.

Bug

The error cannot be understood without being able to see the generated source code.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@asterite asterite added the bug Something isn't working label Sep 12, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 12, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant