Zokrates/ZoKrates

Generic parameter propagation issue

dark64 opened this issue · 0 comments

Description

Generic parameters are not propagated correctly when using structs

Environment

  • Compiler version: 0.8.6
  • Operating system: Ubuntu

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>();
}