noir-lang / noir

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

Panic when returning `zeroed()` in a function using a shorthand unit return type #4791

Closed LogvinovLeon closed 7 months ago

LogvinovLeon commented 7 months ago

Aim

Compiler should not panic when I use zeroed to stub the return value of a function that returns void

Expected Behavior

Does not panic

Bug

Panics:

[repro] Running 1 test function
The application panicked (crashed).
Message:  assertion `left == right` failed
  left: 0
 right: 1
Location: compiler/noirc_evaluator/src/ssa/opt/inlining.rs:420

To Reproduce

use dep::std::unsafe::zeroed;

pub fn get_transaction() {
    zeroed()
}

#[test]
fn success() {
    get_transaction();
}
  1. Create nargo lib project with this code
  2. nargo test

Project Impact

Nice-to-have

Impact Context

I understand that this use-case does not make a lot of sense, but I was trying to debug another compiler panic in my real codebase and while trying to get a minimal repro my initial error which was:

The application panicked (crashed).
Message:  Non-numeric type variable used in expression expecting a value
Location: compiler/noirc_frontend/src/monomorphization/mod.rs:845

Suddenly became this

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

Binary (noirup default)

Nargo Version

noirc version = 0.26.0+c46b164ce56e6a8f81255fb17eb6539bd040f336

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

jfecher commented 7 months ago

The function in question returns a unit type, not void since that is not a type. I think I know why this is panicking though, should be a quick fix.