Skip to content

Stack overflow on generated impl with generic type variable #10748

@asterite

Description

@asterite

Aim

This code:

pub trait StateVariable<Context> {
    fn new(context: Context) -> Self;
}

pub struct PublicImmutable<Context> {
    context: Context,
}

impl<Context> StateVariable<Context> for PublicImmutable<Context> {
    fn new(context: Context) -> Self {
        PublicImmutable { context }
    }
}

pub comptime fn storage(s: TypeDefinition) -> Quoted {
    let (name, typ, _) = s.fields_as_written()[0];

    let context = std::meta::typ::fresh_type_variable();
    assert(
        typ.implements(quote { crate::StateVariable<$context> }.as_trait_constraint()),
        f"Type {typ} was placed in Storage struct but does not implement the StateVariable trait",
    );

    quote {
        impl Storage<$context> { }
    }
}

#[storage]
struct Storage<Context> {
    symbol: PublicImmutable<Context>,
}

struct PrivateContext {}

fn main() {
    let context: PrivateContext = PrivateContext {};
    let s = Storage::init(context);
}

when compiles, gives a stack overflow.

Expected Behavior

It should probably give an error, but never stack overflow.

Bug

A stack overflow happens.

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

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions