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

Enforce multiple return statements #71

Closed
collinc97 opened this issue Jun 24, 2020 · 0 comments
Closed

Enforce multiple return statements #71

collinc97 opened this issue Jun 24, 2020 · 0 comments
Assignees
Labels
feature A new feature.

Comments

@collinc97
Copy link
Collaborator

Overview

Currently a function containing multiple return statements will short circuit upon evaluating the first one.
This is incorrect behavior because we need to evaluate the entirety of each function to satisfy R1CS constraints.

Changes

function main(cond: bool) -> u32 {
    if cond {
        return 1u32
    } else {
        return 0u32
    }
}

In the above function there are two return statements whose results depend on a cond input boolean.
We can conditionally select the desired result from the conditional by passing this cond as an indicator to the function main when it is ready to return.
As expected, return arguments will no longer terminate a function early. Instead, they will pass their result along with their indicator to the function main when it is ready to return.

@collinc97 collinc97 added the feature A new feature. label Jun 24, 2020
@collinc97 collinc97 self-assigned this Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature.
Projects
None yet
Development

No branches or pull requests

2 participants