Skip to content

Generic not found after unquote, inside comptime block #11409

@asterite

Description

@asterite

Aim

In this code:

struct Foo<let N: u32> {}

impl<let N: u32> Foo<N> {
    fn len(self) -> u32 {
        N
    }
}

fn main() {
    comptime {
        let foo: Foo<_> = std::meta::unquote!(quote { Foo::<10> {} });
        println(foo.len())
    }
}

we get:

error: Type annotation needed
   ┌─ src/main.nr:28:17
   │
28 │         println(foo.len())
   │                 ------- Could not determine the value of the generic argument `N` declared on the struct `Foo`
   │

error: Invalid numeric generic
   ┌─ src/main.nr:21:9
   │
21 │         N
   │         - Expected a constant, but found `_`

However, outside a comptime code it works fine:

use std::meta::unquote;

struct Foo<let N: u32> {}

impl<let N: u32> Foo<N> {
    fn len(_self: Self) -> u32 {
        N
    }
}

fn main() {
    let foo: Foo<_> = unquote!(quote { Foo::<10> {} });
    println(foo.len());
}

Expected Behavior

It should compile.

Bug

For some reason N can't be solved, even though it should be known after unifying the result of unquote with the variable.

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

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions