noir-lang / noir

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

Enable function parameter idents in format strings #2024

Closed vezenovm closed 1 year ago

vezenovm commented 1 year ago

Problem

In this PR https://github.com/noir-lang/noir/pull/1952 format strings are being added to enable easy string interpolation for printing. During name resolution a string literal is checked for identifiers and compared in the most recent scope.

When converting these identifiers to expressions we check the definition info of each ident to fetch an expression. However, for function parameters an identifiers expression is not stored as its definition. This leads to this panic:

Message:  ICE: format string field requires expression
Location: crates/noirc_frontend/src/monomorphization/mod.rs:268

when attempting to do something like this:

fn print_in_func(x: Field, y: Field) {
    std::println(f"x: {x}, y: {y}");
}

This requires having to set function parameters to intermediate variables before printing them.

Happy Case

We should be able to print function parameters like any other identifier.

Alternatives Considered

N/A

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

vezenovm commented 1 year ago

Fixed now as part of #1952

kevaundray commented 1 year ago

Re-opening since 1952 has not been merged

vezenovm commented 1 year ago

Resolved now as #1952 is merged