-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for propagation of type constraints in type inference (#6502)
## Description This PR adds tests that prove that #6379 is fixed. The actual fix happened in #6490. Closes #6379. ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
9 changed files
with
90 additions
and
14 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
...e_vm_tests/test_programs/should_pass/language/function_return_type_unification/.gitignore
This file was deleted.
Oops, something went wrong.
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
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
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
4 changes: 2 additions & 2 deletions
4
...2e_vm_tests/test_programs/should_pass/language/function_return_type_unification/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 1 } | ||
expected_result_new_encoding = { action = "return_data", value = "01" } | ||
expected_result = { action = "return", value = 31 } | ||
expected_result_new_encoding = { action = "return_data", value = "0000001f" } | ||
validate_abi = false |
8 changes: 8 additions & 0 deletions
8
...st_programs/should_pass/language/type_inference_propagation_of_type_constraints/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,8 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-9D1294DAC07670CA" | ||
|
||
[[package]] | ||
name = "type_inference_propagation_of_type_constraints" | ||
source = "member" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
...st_programs/should_pass/language/type_inference_propagation_of_type_constraints/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] | ||
name = "type_inference_propagation_of_type_constraints" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } |
64 changes: 64 additions & 0 deletions
64
..._programs/should_pass/language/type_inference_propagation_of_type_constraints/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,64 @@ | ||
// This tests proves that https://github.com/FuelLabs/sway/issues/6379 is fixed. | ||
|
||
script; | ||
|
||
trait Build { | ||
fn build() -> Self; | ||
} | ||
|
||
fn produce<T>() -> T where T: Build { | ||
T::build() | ||
} | ||
|
||
impl Build for u8 { | ||
fn build() -> Self { | ||
7 | ||
} | ||
} | ||
|
||
impl Build for u32 { | ||
fn build() -> Self { | ||
31 | ||
} | ||
} | ||
|
||
impl Build for u64 { | ||
fn build() -> Self { | ||
63 | ||
} | ||
} | ||
|
||
fn consume_u8(a: u8) -> u8 { | ||
a | ||
} | ||
|
||
fn consume_u32(a: u32) -> u32 { | ||
a | ||
} | ||
|
||
fn consume_u64(a: u64) -> u64 { | ||
a | ||
} | ||
|
||
fn main() -> (u8, u32, u64) { | ||
let a = produce_consume_u8(); | ||
let b = produce_consume_u32(); | ||
let c = produce_consume_u64(); | ||
|
||
(a, b, c) | ||
} | ||
|
||
fn produce_consume_u8() -> u8 { | ||
let x = produce(); | ||
consume_u8(x) | ||
} | ||
|
||
fn produce_consume_u32() -> u32 { | ||
let x = produce(); | ||
consume_u32(x) | ||
} | ||
|
||
fn produce_consume_u64() -> u64 { | ||
let x = produce(); | ||
consume_u64(x) | ||
} |
4 changes: 4 additions & 0 deletions
4
...st_programs/should_pass/language/type_inference_propagation_of_type_constraints/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,4 @@ | ||
category = "run" | ||
expected_result = { action = "return_data", value = "0700000000000000 000000000000001f 000000000000003f" } | ||
expected_result_new_encoding = { action = "return_data", value = "07 0000001f 000000000000003f" } | ||
validate_abi = false |