Zokrates / ZoKrates

A toolbox for zkSNARKs on Ethereum
https://zokrates.github.io
GNU Lesser General Public License v3.0
1.81k stars 361 forks source link

Generic parameter propagation issue #1303

Open dark64 opened 1 year ago

dark64 commented 1 year ago

Description

Generic parameters are not propagated correctly when using structs

Environment

Steps to Reproduce

struct Foo<N> {
    field[N] inner;
}

def test<N>() -> Foo<N> {
    return Foo { inner: [0; N] };
}

def main() -> Foo<2> {
    return test::<2>();
}

Fails to compile with message

Generic parameters must be compile-time constants, found test::<2>()

Assigning the result before returning works:

struct Foo<N> {
    field[N] inner;
}

def test<N>() -> Foo<N> {
    return Foo { inner: [0; N] };
}

def main() -> Foo<2> {
    Foo<2> foo = test::<2>();
    return foo;
}

Using an array directly without the struct compiles fine as expected which might suggest something regarding structs is not right:

def test<N>() -> field[N] {
    return [0; N];
}

def main() -> field[2] {
    return test::<2>();
}