-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
115efc3
test: struct destructuring
matt-user bcec9bf
feat: add print statements for debugging
matt-user 58dfcee
debugging: add print
matt-user 9ae75e5
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user cb889fb
Merge remote-tracking branch 'origin/master' into mattauer/struct_des…
483d18b
Add Forc.lock.
74188c1
Add descriptions.
e06e04b
fix: remove println! statements
matt-user df1d3d5
chore: update to latest version
matt-user 69aeccc
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user 2af43ac
feat: add not working Pattern:Struct branch to match
matt-user 204a251
fix: identation in oracle json
matt-user bd01ad5
feat: create pattern if field has none
matt-user 60eaa9b
refactor: remove debug prints
matt-user d715323
fix: warnings
matt-user 06292e8
test: type annotations for destructure
matt-user 9f91f64
fix: handle type annotations
matt-user 8e159fd
chore: run formatter
matt-user 22c76dd
fix: remove test cargo toml
matt-user 4cad09a
Merge branch 'master' into mattauer/struct_destructuring
matt-user 60adadb
fix: destructure test case
matt-user 5d8b0c3
test: nested struct destructuring
matt-user 9d6b86a
docs: add struct destructuring
matt-user 0730cb6
refactor: fix formatting
matt-user 32fcea7
fix: formatting
matt-user 5350b4c
refactor examples
matt-user f614df8
fix: formatting
matt-user 3904206
fix: remove mention of deleted file
matt-user 1a5b93e
test: nested tuple in struct and vis versa
matt-user 11c5567
docs: add nested tuple in struct and vis versa to examples
matt-user b48937a
fix: formatting
matt-user 802009d
fix: formatting
matt-user b9a0e6a
fix: formatting
matt-user 7cd5ad6
fix: formatting
matt-user 9139e18
Merge branch 'master' into mattauer/struct_destructuring
matt-user 12b6f35
Merge branch 'mattauer/struct_destructuring' of https://github.com/Fu…
matt-user 6575499
Merge branch 'master' into mattauer/struct_destructuring
matt-user fd69348
Merge branch 'master' into mattauer/struct_destructuring
otrho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...src/e2e_vm_tests/test_programs/should_pass/language/nested_struct_destructuring/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F93ECA3248F311E3' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'struct_destructuring' | ||
source = 'root' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
...src/e2e_vm_tests/test_programs/should_pass/language/nested_struct_destructuring/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "struct_destructuring" | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } |
15 changes: 15 additions & 0 deletions
15
...tests/test_programs/should_pass/language/nested_struct_destructuring/json_abi_oracle.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "main", | ||
"outputs": [ | ||
{ | ||
"components": null, | ||
"name": "", | ||
"type": "u64", | ||
"typeArguments": null | ||
} | ||
], | ||
"type": "function" | ||
} | ||
] |
21 changes: 21 additions & 0 deletions
21
...c/e2e_vm_tests/test_programs/should_pass/language/nested_struct_destructuring/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
script; | ||
|
||
// Tests nested struct destructuring | ||
|
||
fn main() -> u64 { | ||
let point1 = Point { x: 0, y: 0 }; | ||
let point2 = Point { x: 1, y: 1 }; | ||
let line = Line { p1: point1, p2: point2 }; | ||
let Line { p1: Point { x: x0, y: y0 }, p2: Point { x: x1, y: y1} } = line; | ||
x0 | ||
} | ||
|
||
struct Point { | ||
x: u64, | ||
y: u64, | ||
} | ||
|
||
struct Line { | ||
p1: Point, | ||
p2: Point, | ||
} |
3 changes: 3 additions & 0 deletions
3
...src/e2e_vm_tests/test_programs/should_pass/language/nested_struct_destructuring/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 0 } | ||
validate_abi = true |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!