Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support functions with optional arguments #2145

Closed
TomAFrench opened this issue Aug 3, 2023 · 3 comments
Closed

Support functions with optional arguments #2145

TomAFrench opened this issue Aug 3, 2023 · 3 comments
Assignees
Labels
discussion enhancement New feature or request

Comments

@TomAFrench
Copy link
Member

Problem

As described in #1939, we want to be able to provide an optional assert message to be displayed in the situation where a constraint is unsatisfied.

assert is in the process of being changed into a built-in function, we then need to be able to have two version of assert_eq both with and without the assert message.

Happy Case

Ideally we'd be able to have an optional argument to assert_eq as so

#[builtin(assert_eq)]
fn assert_eq<T>(lhs: T, rhs: T, msg?: str) {}

Alternatives Considered

We could also allow shadowing of a function name as long as the signature was different.

fn assert_eq<T>(lhs: T, rhs: T) {
    assert_eq(lhs, rhs, "")
}

#[builtin(assert_eq)]
fn assert_eq<T>(lhs: T, rhs: T, msg?: str) {}

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@TomAFrench TomAFrench added the enhancement New feature or request label Aug 3, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 3, 2023
@jfecher
Copy link
Contributor

jfecher commented Aug 3, 2023

We could also simply not convert assert_eq into a builtin function and keep it as a keyword. Supporting an optional extra message argument is the reason assert is still a keyword for example.

@kevaundray
Copy link
Contributor

Changed to P-LOW due to this being a nice to have if we have it as a keyword. The thing that Rust has that we don't which makes it possible in Rust without optional arguments is macro_rules

@kevaundray
Copy link
Contributor

Closing this as not actionable, we can re-open if we do decide to have optional arguments

@kevaundray kevaundray closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

4 participants