-
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.
Adds function return type unification. (#6490)
## Description The function return type unification was missing, leading to generic functions not being resolved based on the return type. ## Checklist - [x] I have linked to any relevant issues. - [x] 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. - [x] 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. --------- Co-authored-by: Joshua Batty <[email protected]> Co-authored-by: IGI-111 <[email protected]>
- Loading branch information
1 parent
253330d
commit a81c42e
Showing
9 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
test/src/e2e_vm_tests/test_programs/should_fail/bad_generic_annotation/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
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
7 changes: 7 additions & 0 deletions
7
test/src/e2e_vm_tests/test_programs/should_fail/recursive_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
2 changes: 2 additions & 0 deletions
2
...e_vm_tests/test_programs/should_pass/language/function_return_type_unification/.gitignore
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,2 @@ | ||
out | ||
target |
13 changes: 13 additions & 0 deletions
13
...2e_vm_tests/test_programs/should_pass/language/function_return_type_unification/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,13 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-D73E65B1F4E48513" | ||
|
||
[[package]] | ||
name = "function_return_type_unification" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-D73E65B1F4E48513" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
...2e_vm_tests/test_programs/should_pass/language/function_return_type_unification/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 = "function_return_type_unification" | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../reduced_std_libs/sway-lib-std-assert" } |
29 changes: 29 additions & 0 deletions
29
..._vm_tests/test_programs/should_pass/language/function_return_type_unification/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,29 @@ | ||
script; | ||
|
||
trait Build { | ||
fn build() -> Self; | ||
} | ||
|
||
impl Build for u32 { | ||
fn build() -> Self { | ||
31 | ||
} | ||
} | ||
|
||
impl Build for u64 { | ||
fn build() -> Self { | ||
63 | ||
} | ||
} | ||
|
||
fn produce<T>() -> T | ||
where T: Build, | ||
{ | ||
T::build() | ||
} | ||
|
||
fn main() -> bool { | ||
let _:u32 = produce(); | ||
|
||
true | ||
} |
4 changes: 4 additions & 0 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 1 } | ||
expected_result_new_encoding = { action = "return_data", value = "01" } | ||
validate_abi = false |