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: defining a struct by its member names in a different order than the definition is swapping field values #6623

Closed
feltroidprime opened this issue Nov 10, 2024 · 1 comment · Fixed by #6625
Labels
bug Something isn't working

Comments

@feltroidprime
Copy link
Contributor

feltroidprime commented Nov 10, 2024

Bug Report

Cairo version:

2.8.4

Current behavior:

Defining structs by their member names in a different order than the one in the struct definition is not respecting the member names when accessing them later on.

Expected behavior:

struct members should follow argument names, the compiler should re-order them when a struct is created with explicit members names, otherwise it can be extremely misleading.

Steps to reproduce:

#[cfg(test)]
mod tests {
    struct S {
        a: u64,
        b: u64,
    }

    const X: S = S { b: 31, a: 252, };


    #[test]
    fn test_const() {
        println!("a : {:?}", X.a); // outputs '31'  (expected 252)
        println!("b : {:?}", X.b); // outputs  '252'  (expected 31)
    }
}

@feltroidprime feltroidprime added the bug Something isn't working label Nov 10, 2024
@feltroidprime feltroidprime changed the title bug: const Struct has inverted field members. bug: const Struct has swapped field members values. Nov 10, 2024
@feltroidprime feltroidprime changed the title bug: const Struct has swapped field members values. bug: defining a struct by its member names in a different order than the definition is swapping field values Nov 10, 2024
@orizi orizi linked a pull request Nov 11, 2024 that will close this issue
@orizi
Copy link
Collaborator

orizi commented Nov 11, 2024

Thanks for the report!
Note this is a bug that only occurs in consts definition - in any case attached fixing PR.

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.

2 participants