Skip to content

Cannot run macros within comptime code #5575

@jfecher

Description

@jfecher

Aim

comptime fn foo(x: Field) {
    let cond = quote { x == 5 };
    assert(std::meta::unquote!(cond));
}

Expected Behavior

The code to run correctly assuming x = 5

Bug

We get an error that x is not a comptime variable.

This is because the function is elaborated before it is interpreted. The elaborator sees the macro call and tries to run it but doesn't know the value of x yet. If we instead delay this expansion until the interpreter is called then we can't resolve the x == 5 snippet since the interpreter itself can't elaborate code.

To Reproduce

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions