-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Demonstrate that T for Vec can now be inferred by arguments
#2132
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions
2
test/src/e2e_vm_tests/test_programs/should_fail/vec/.gitignore
This file contains hidden or 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,2 @@ | ||
| out | ||
| target |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_fail/vec/Forc.lock
This file contains hidden or 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,14 @@ | ||
| [[package]] | ||
| name = 'core' | ||
| source = 'path+from-root-E8B33641BFB485A7' | ||
| dependencies = [] | ||
|
|
||
| [[package]] | ||
| name = 'std' | ||
| source = 'path+from-root-E8B33641BFB485A7' | ||
| dependencies = ['core'] | ||
|
|
||
| [[package]] | ||
| name = 'vec' | ||
| source = 'root' | ||
| dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/vec/Forc.toml
This file contains hidden or 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 <[email protected]>"] | ||
| entry = "main.sw" | ||
| license = "Apache-2.0" | ||
| name = "vec" | ||
|
|
||
| [dependencies] | ||
| std = { path = "../../../../../../sway-lib-std" } |
113 changes: 113 additions & 0 deletions
113
test/src/e2e_vm_tests/test_programs/should_fail/vec/src/main.sw
This file contains hidden or 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,113 @@ | ||
| script; | ||
|
|
||
| use std::{assert::assert, hash::sha256, option::Option, revert::revert, vec::Vec}; | ||
|
|
||
| struct SimpleStruct { | ||
| x: u32, | ||
| y: b256, | ||
| } | ||
|
|
||
| enum SimpleEnum { | ||
| X: (), | ||
| Y: b256, | ||
| Z: (b256, | ||
| b256), | ||
| } | ||
|
|
||
| fn main() -> bool { | ||
| test_vector_new_u8(); | ||
| true | ||
| } | ||
|
|
||
| fn test_vector_new_u8() { | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let number0 = 0u8; | ||
| let number1 = 1u8; | ||
| let number2 = 2u8; | ||
| let number3 = 3u8; | ||
| let number4 = 4u8; | ||
| let number5 = 5u8; | ||
| let number6 = 6u8; | ||
| let number7 = 7u8; | ||
| let number8 = 8u8; | ||
|
|
||
| assert(vector.len() == 0); | ||
| assert(vector.capacity() == 0); | ||
| assert(vector.is_empty()); | ||
|
|
||
| vector.push(number0); | ||
| vector.push(number1); | ||
| vector.push(number2); | ||
| vector.push(number3); | ||
| vector.push(number4); | ||
| vector.push(false); | ||
|
|
||
| assert(vector.len() == 5); | ||
| assert(vector.capacity() == 8); | ||
| assert(vector.is_empty() == false); | ||
|
|
||
| match vector.get(0) { | ||
| Option::Some(val) => assert(val == number0), Option::None => revert(0), | ||
| } | ||
|
|
||
| // Push after get | ||
| vector.push(number5); | ||
| vector.push(number6); | ||
| vector.push(number7); | ||
| vector.push(number8); | ||
| vector.push("this should break it 1"); | ||
|
|
||
| match vector.get(4) { | ||
| Option::Some(val) => assert(val == number4), Option::None => revert(0), | ||
| } | ||
|
|
||
| match vector.get(number6) { | ||
| Option::Some(val) => assert(val == number6), Option::None => revert(0), | ||
| } | ||
|
|
||
| assert(vector.len() == 9); | ||
| assert(vector.capacity() == 16); | ||
| assert(!vector.is_empty()); | ||
|
|
||
| // Test after capacity change | ||
| match vector.get(4) { | ||
| Option::Some(val) => assert(val == number4), Option::None => revert(0), | ||
| } | ||
|
|
||
| match vector.get(6) { | ||
| Option::Some(val) => assert(val == number6), Option::None => revert(0), | ||
| } | ||
|
|
||
| vector.clear(); | ||
|
|
||
| // Empty after clear | ||
| assert(vector.len() == 0); | ||
| assert(vector.capacity() == 16); | ||
| assert(vector.is_empty() == true); | ||
|
|
||
| match vector.get(0) { | ||
| Option::Some(val) => revert(0), Option::None => (), | ||
| } | ||
|
|
||
| // Make sure pushing again after clear() works | ||
| vector.push(number0); | ||
| vector.push(number1); | ||
| vector.push(number2); | ||
| vector.push(number3); | ||
| vector.push(number4); | ||
| vector.push("this should break it 2"); | ||
|
|
||
| assert(vector.len() == 5); | ||
| assert(vector.capacity() == 16); | ||
| assert(vector.is_empty() == false); | ||
|
|
||
| match vector.get(4) { | ||
| Option::Some(val) => assert(val == number4), Option::None => revert(0), | ||
| } | ||
|
|
||
| // Out of bounds access | ||
| match vector.get(5) { | ||
| Option::Some(val) => revert(0), Option::None => (), | ||
| } | ||
| } | ||
10 changes: 10 additions & 0 deletions
10
test/src/e2e_vm_tests/test_programs/should_fail/vec/test.toml
This file contains hidden or 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,10 @@ | ||
| category = "fail" | ||
|
|
||
| # check: vector.push(false); | ||
| # nextln: $()This parameter was declared as type u8, but argument of type bool was provided. | ||
|
|
||
| # check: vector.push("this should break it 1"); | ||
| # nextln: $()This parameter was declared as type u8, but argument of type str[22] was provided. | ||
|
|
||
| # check: vector.push("this should break it 2"); | ||
| # nextln: $()This parameter was declared as type u8, but argument of type str[22] was provided. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ fn main() -> bool { | |
| } | ||
|
|
||
| fn test_vector_new_u8() { | ||
| let mut vector: Vec<u8> = ~Vec::new::<u8>(); | ||
| let mut vector = ~Vec::new(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice! |
||
|
|
||
| let number0 = 0u8; | ||
| let number1 = 1u8; | ||
|
|
@@ -117,7 +117,7 @@ fn test_vector_new_u8() { | |
| } | ||
|
|
||
| fn test_vector_new_b256() { | ||
| let mut vector: Vec<b256> = ~Vec::new::<b256>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let b0 = 0x0000000000000000000000000000000000000000000000000000000000000000; | ||
| let b1 = 0x0000000000000000000000000000000000000000000000000000000000000001; | ||
|
|
@@ -207,7 +207,7 @@ fn test_vector_new_b256() { | |
| } | ||
|
|
||
| fn test_vector_new_struct() { | ||
| let mut vector: Vec<SimpleStruct> = ~Vec::new::<SimpleStruct>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let number0 = 0u32; | ||
| let number1 = 1u32; | ||
|
|
@@ -359,7 +359,7 @@ fn test_vector_new_struct() { | |
| } | ||
|
|
||
| fn test_vector_new_enum() { | ||
| let mut vector: Vec<SimpleEnum> = ~Vec::new::<SimpleEnum>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let b0 = 0x0000000000000000000000000000000000000000000000000000000000000000; | ||
| let b1 = 0x0000000000000000000000000000000000000000000000000000000000000001; | ||
|
|
@@ -412,7 +412,7 @@ fn test_vector_new_enum() { | |
| } | ||
|
|
||
| fn test_vector_new_tuple() { | ||
| let mut vector: Vec<(u16, b256)> = ~Vec::new::<(u16, b256)>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let number0 = 0u16; | ||
| let number1 = 1u16; | ||
|
|
@@ -536,7 +536,7 @@ fn test_vector_new_tuple() { | |
| } | ||
|
|
||
| fn test_vector_new_string() { | ||
| let mut vector: Vec<str[4]> = ~Vec::new::<str[4]>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let s0 = "fuel"; | ||
| let s1 = "john"; | ||
|
|
@@ -578,9 +578,7 @@ fn test_vector_new_string() { | |
| } | ||
|
|
||
| fn test_vector_new_array() { | ||
| let mut vector: Vec<[u64; | ||
| 3]> = ~Vec::new::<[u64; | ||
| 3]>(); | ||
| let mut vector = ~Vec::new(); | ||
|
|
||
| let a0 = [0, 1, 2]; | ||
| let a1 = [3, 4, 5]; | ||
|
|
@@ -628,7 +626,7 @@ fn test_vector_new_array() { | |
| } | ||
|
|
||
| fn test_vector_with_capacity_u64() { | ||
| let mut vector: Vec<u64> = ~Vec::with_capacity::<u64>(8); | ||
| let mut vector = ~Vec::with_capacity(8); | ||
|
|
||
| let number0 = 0; | ||
| let number1 = 1; | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.