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

[Bug] loop mismatched types found for operation #758

Closed
0rphon opened this issue Mar 11, 2021 · 3 comments · Fixed by #862
Closed

[Bug] loop mismatched types found for operation #758

0rphon opened this issue Mar 11, 2021 · 3 comments · Fixed by #862
Assignees
Labels
bug Something isn't working

Comments

@0rphon
Copy link
Contributor

0rphon commented Mar 11, 2021

🐛 Bug Report

Code snippet to reproduce

function main (
    x: u8,
) {
    for y in 0u8..10u8 {
        let z = y > x;
    }
}

Stack trace & error message

D:\Work\leo_playground>D:\Work\leo_repos\leo\target\release\leo clean && D:\Work\leo_repos\leo\target\release\leo run
      Done Finished in 5 milliseconds 

     Build Starting...
     Build Compiling main program... ("D:\\Work\\leo_playground\\src/main.leo")
      Done Finished in 6 milliseconds

Error:     -->  5:17
     |
     |                  ^^^^^
     |
     = Mismatched types found for operation `>`

Your Environment

  • leo commit c47ab84
  • rustc version 1.50.0
  • Windows 10.0.19042 (Windows 10 Pro) [64-bit]
@0rphon 0rphon added the bug Something isn't working label Mar 11, 2021
@0rphon 0rphon changed the title [Bug] [Bug] loop mismatched types found for operation Mar 11, 2021
@ljedrz
Copy link
Contributor

ljedrz commented Mar 12, 2021

This is indeed the same issue / root cause as #772; the loop index is assigned the type U32 instead of U8.

@ljedrz
Copy link
Contributor

ljedrz commented Mar 12, 2021

Confirmed: the only thing that needs to be done is to complete the todo in ConstrainedProgram::enforce_iteration_statement; I tested it with a simple:

let uint = match variable.type_ {
    Type::Integer(IntegerType::U8) => Integer::U8(UInt8::constant(i as u8)),
    Type::Integer(IntegerType::U16) => Integer::U16(UInt16::constant(i as u16)),
    Type::Integer(IntegerType::U32) => Integer::U32(UInt32::constant(i as u32)),
    Type::Integer(IntegerType::U64) => Integer::U64(UInt64::constant(i as u64)),
    _ => unimplemented!(),
};

self.store(
    variable.id,
    ConstrainedValue::Integer(uint),
);

and the error was fixed; it would also fix #772. I'll leave this one to leo maintainers, as there's extra considerations I'm not sure about, including:

  • are the index values validated (i.e. from <= to) by this point?
  • how to treat negative index values?
  • should i128/u128 indices be handled or rejected?

But otherwise that's the only issue; loop indices get parsed correctly.

@collinc97
Copy link
Collaborator

Type casting #600 has not been implemented at the gadget level yet. This bug will be blocked until that is implemented.

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
None yet
Development

Successfully merging a pull request may close this issue.

4 participants