-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat: struct destructuring #2243
Conversation
…elLabs/sway into mattauer/struct_destructuring
…elLabs/sway into mattauer/struct_destructuring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the changes -- clean, in line with @emilyaherbert's awesome tuple destructuring impl, and well commented.
Two things --
- Could you document this in the
docs/
folder as a part of this PR? - Does this support nested destructuring? If so, we should test it. If not, we should document that limitation for both structs and tuples.
let tuple_tys_opt = match ty_opt { | ||
Some(Ty::Tuple(tys)) => Some(tys.into_inner().to_tys()), | ||
_ => None, | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for these comments, great addition
@@ -0,0 +1,3 @@ | |||
category = "run" | |||
expected_result = { action = "return", value = 42 } | |||
validate_abi = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this isn't a contract, do we need to validate the abi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'm not sure, there are other test cases in the same folder such as tuple_access that are scripts and validate the abi.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't think it is necessary. Cc @otrho for consensus on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Time for an RFC!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been validating the ABI for all passing tests including scripts because scripts emit a JSON ABI now. Not sure how important that is though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, all I did was refactor the test harness. This doesn't make me the authority on how or what to test. 😉
let line = Line { p1: point1, p2: point2 }; | ||
let Line { p1: Point { x: x0, y: y0 }, p2: Point { x: x1, y: y1} } = line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, don't hate me, but what about a nested tuple in a struct and vice versa?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can add a test for that. Should I also include an example for the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs example could be cool, to show people just how deep destructuring can go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪🏻
@@ -0,0 +1,3 @@ | |||
category = "run" | |||
expected_result = { action = "return", value = 42 } | |||
validate_abi = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, all I did was refactor the test harness. This doesn't make me the authority on how or what to test. 😉
closes issue #1167
There is definitely some repeated code between the Struct and Tuple Pattern branches in the statement_let_to_ast_nodes function. Let me know if I should add some helper functions.