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

Unused math expression doesn't warn or error #6846

Open
asterite opened this issue Dec 17, 2024 · 1 comment
Open

Unused math expression doesn't warn or error #6846

asterite opened this issue Dec 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@asterite
Copy link
Collaborator

Aim

This code:

fn main() -> pub Field {
    let x = 1;
    if x != 0 {
        -1 * x
    }
    1
}

Expected Behavior

Should give a warning or an error, because -1 * x has no effect at all. An equivalent code in Rust gives an error saying "mismatched types" because one branch returns an integer, the other ().

Bug

Noir should check if branches have the same type, even if the if is a statement and not an expression.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@asterite asterite added the bug Something isn't working label Dec 17, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Dec 17, 2024
@asterite
Copy link
Collaborator Author

Interestingly, this is also valid Noir code:

fn main() {
    let x = if true { 1 };
}

The type of x ends up being () while Rust rejects it.

I guess "fixing" all of these might introduce some breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant