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

destructuring of less fields than are in struct throws an error from interpreter #968

Closed
Gusarich opened this issue Oct 16, 2024 · 0 comments · Fixed by #969
Closed

destructuring of less fields than are in struct throws an error from interpreter #968

Gusarich opened this issue Oct 16, 2024 · 0 comments · Fixed by #969
Assignees
Labels
bug Something isn't working or isn't right scope: const-eval The constant and partial evaluation optimization mechanisms
Milestone

Comments

@Gusarich
Copy link
Member

Gusarich commented Oct 16, 2024

Curiosly, that depends. The following example (taken from docs):

struct Two { first: Int; second: String }

fun discard(s: Two) {
    let Two { first } = s;
    // ^^^^^^^^^^^^^^^^^^^
}

Will report an error: "Cannot evaluate expression to a constant: destructuring assignment expected 2 fields, but got 1".

But if one would place the same destructuring statement in the receive() function, there would be no such error:

struct Two { first: Int; second: String }
message HasTwo { s: Two }

contract Example {
   receive() {}
   receive(msg: HasTwo) {
       // Almost the same line as in the previous example
       let Two { first } = msg.s;
       
       // No errors before or here
       dump(first);
   }
}

Originally posted by @novusnota in #964 (comment)

@Gusarich Gusarich changed the title restructuring of less fields than are in struct throws an error from interpreter destructuring of less fields than are in struct throws an error from interpreter Oct 16, 2024
@anton-trunov anton-trunov added this to the v1.6.0 milestone Oct 17, 2024
@anton-trunov anton-trunov added scope: const-eval The constant and partial evaluation optimization mechanisms bug Something isn't working or isn't right labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or isn't right scope: const-eval The constant and partial evaluation optimization mechanisms
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants