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

feat: struct destructuring #2243

Merged
merged 38 commits into from
Jul 8, 2022
Merged

feat: struct destructuring #2243

merged 38 commits into from
Jul 8, 2022

Conversation

matt-user
Copy link
Contributor

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.

@matt-user matt-user added the language feature Core language features visible to end users label Jul 6, 2022
@matt-user matt-user requested a review from a team July 6, 2022 18:42
@matt-user matt-user self-assigned this Jul 6, 2022
@adlerjohn adlerjohn linked an issue Jul 6, 2022 that may be closed by this pull request
Copy link
Contributor

@sezna sezna left a 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 --

  1. Could you document this in the docs/ folder as a part of this PR?
  2. 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,
};

Copy link
Contributor

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

sway-parse/src/item/mod.rs Show resolved Hide resolved
@@ -0,0 +1,3 @@
category = "run"
expected_result = { action = "return", value = 42 }
validate_abi = true
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time for an RFC!

Copy link
Contributor

@mohammadfawaz mohammadfawaz Jul 6, 2022

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.

Copy link
Contributor

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. 😉

Comment on lines 8 to 9
let line = Line { p1: point1, p2: point2 };
let Line { p1: Point { x: x0, y: y0 }, p2: Point { x: x1, y: y1} } = line;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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!

@matt-user matt-user requested a review from sezna July 7, 2022 17:11
sezna
sezna previously approved these changes Jul 7, 2022
Copy link
Contributor

@sezna sezna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪🏻

@matt-user matt-user requested a review from sezna July 7, 2022 20:01
@matt-user matt-user enabled auto-merge (squash) July 7, 2022 20:02
@matt-user matt-user disabled auto-merge July 7, 2022 21:01
@matt-user matt-user enabled auto-merge (squash) July 7, 2022 21:01
@matt-user matt-user requested a review from a team July 7, 2022 22:23
@@ -0,0 +1,3 @@
category = "run"
expected_result = { action = "return", value = 42 }
validate_abi = true
Copy link
Contributor

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. 😉

@matt-user matt-user merged commit aadca68 into master Jul 8, 2022
@matt-user matt-user deleted the mattauer/struct_destructuring branch July 8, 2022 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language feature Core language features visible to end users
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Struct destructuring
5 participants