-
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.
We already do unification of expressions with type annotation when necessary, but these were not affecting enum variants because we used separate TypeIds for the expression and for the enum variant. With this change the enum variant and the expressions will share the same TypeId, making unification to the expression to also affect the enum variant. Fixes #5492 Fixes #5581 Probably helpful for #5559
- Loading branch information
Showing
5 changed files
with
67 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
16 changes: 16 additions & 0 deletions
16
test/src/e2e_vm_tests/test_programs/should_pass/language/enum_variant_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,16 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-F6BA7257B3F9949F" | ||
|
||
[[package]] | ||
name = "enum_variant_unification" | ||
source = "member" | ||
dependencies = [ | ||
"core", | ||
"std", | ||
] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-F6BA7257B3F9949F" | ||
dependencies = ["core"] |
9 changes: 9 additions & 0 deletions
9
test/src/e2e_vm_tests/test_programs/should_pass/language/enum_variant_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,9 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "enum_variant_unification" | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } | ||
std = { path = "../../../../../../../sway-lib-std" } |
33 changes: 33 additions & 0 deletions
33
.../src/e2e_vm_tests/test_programs/should_pass/language/enum_variant_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,33 @@ | ||
script; | ||
|
||
struct S<T> { | ||
x: T, | ||
} | ||
|
||
fn main() -> u64 { | ||
// https://github.com/FuelLabs/sway/issues/5492 | ||
let _ = foo(); | ||
let _ = bar(true); | ||
|
||
// https://github.com/FuelLabs/sway/issues/5581 | ||
let _: S<Option<u8>> = S { x: Option::Some(1) }; | ||
|
||
0 | ||
} | ||
|
||
#[inline(never)] | ||
fn foo() -> Option<u8> { | ||
match Some(true) { | ||
Option::Some(_b) => Option::Some(17), | ||
Option::None => Option::None, | ||
} | ||
} | ||
|
||
#[inline(never)] | ||
fn bar(b: bool) -> Option<u8> { | ||
if(b) { | ||
Option::Some(19) | ||
} else { | ||
Option::None | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/src/e2e_vm_tests/test_programs/should_pass/language/enum_variant_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 = 0 } | ||
validate_abi = false | ||
expected_warnings = 3 |