noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
875 stars 188 forks source link

Calling lambda from array or slice panics #5503

Open michaeljklein opened 2 months ago

michaeljklein commented 2 months ago

Aim

Call a closure from an array or slice of closures:

fn main() {
    // Also panics:
    // let lambdas: [fn(()) -> ()] = &[];

    // Also panics when there's a lambda in the array
    // let example_lambda: fn(u8) -> u8 = |x| { x + 1 };
    // let lambdas: [fn(u8) -> u8; 8] = [example_lambda; 8];

    let lambdas: [fn(()) -> (); 0] = [];

    lambdas[0](());

    // Also panics
    // for f in lambdas {
    //     f(());
    // }
}

Expected Behavior

Either:

  1. The closure to be successfully accessed from the array/slice and called
  2. A user error explaining that this was unsupported

Bug

The application panicked (crashed).
Message:  ICE: at least one variant should exist for a dynamic call Signature { params: [], returns: [] }
Location: compiler/noirc_evaluator/src/ssa/opt/defunctionalize.rs:253

To Reproduce

1. 2. 3. 4.

Project Impact

Nice-to-have

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

None

Nargo Version

nargo version = 0.31.0 noirc version = 0.31.0+0541568b4c209927a70778b895e8f1e50d9b6543 (git version hash: 0541568b4c209927a70778b895e8f1e50d9b6543, is dirty: false)

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

vezenovm commented 2 months ago

This looks like the same issue as here (https://github.com/noir-lang/noir/issues/5212)