forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing a generic types resolution bug (FuelLabs#736)
* Initial fix * Some fixes + adding a test * Initial fix * Some fixes + adding a test * fmt * fixing more cases and imporving the test * clippy * Addressing review comment
- Loading branch information
1 parent
f0707fc
commit 030e00a
Showing
6 changed files
with
188 additions
and
22 deletions.
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
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
5 changes: 5 additions & 0 deletions
5
test/src/e2e_vm_tests/test_programs/funcs_with_generic_types/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,5 @@ | ||
[project] | ||
author = "Fuel Labs <[email protected]>" | ||
license = "Apache-2.0" | ||
name = "funcs_with_generic_types" | ||
entry = "main.sw" |
1 change: 1 addition & 0 deletions
1
test/src/e2e_vm_tests/test_programs/funcs_with_generic_types/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 @@ | ||
[] |
103 changes: 103 additions & 0 deletions
103
test/src/e2e_vm_tests/test_programs/funcs_with_generic_types/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,103 @@ | ||
script; | ||
|
||
/* ------------------*/ | ||
|
||
struct Foo1 { | ||
a: u64, | ||
b: u64, | ||
} | ||
|
||
impl Foo1 { | ||
fn trivial(self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
fn func1() -> bool { | ||
let f = Foo1 {a: 0, b: 0}; | ||
f.trivial() | ||
} | ||
|
||
/* ------------------*/ | ||
|
||
enum Bar { | ||
a: (), | ||
b: (), | ||
} | ||
|
||
impl Bar { | ||
fn trivial(self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
fn func2(m: Bar) -> bool { | ||
m.trivial() | ||
} | ||
|
||
/* ------------------*/ | ||
|
||
struct Foo2<T> { | ||
foo: T, | ||
} | ||
|
||
impl Foo2<T> { | ||
fn trivial(self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
fn func3(a: Foo2<u8>) -> Foo2<bool> { | ||
if a.trivial() { | ||
Foo2 {foo: false} | ||
} else { | ||
Foo2 {foo: true} | ||
} | ||
} | ||
|
||
fn func4(b: Foo2<bool>) -> Foo2<u8> { | ||
if b.trivial() { | ||
Foo2 {foo: 0u8} | ||
} else { | ||
Foo2 {foo: 1u8} | ||
} | ||
} | ||
|
||
/* ------------------*/ | ||
|
||
pub enum Rezult<T, E> { | ||
Ok: T, | ||
Err: E, | ||
} | ||
|
||
pub enum DumbError { | ||
Error: (), | ||
} | ||
|
||
impl Rezult<T, E> { | ||
fn trivial(self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
pub fn func5(r: Rezult<u8, DumbError>) -> Rezult<u8, DumbError> { | ||
if r.trivial() { | ||
Rezult::Err(DumbError::Error) | ||
} else { | ||
Rezult::Ok(1u8) | ||
} | ||
} | ||
|
||
pub fn func6(r: Rezult<bool, DumbError>) -> Rezult<bool, DumbError> { | ||
if r.trivial() { | ||
Rezult::Err(DumbError::Error) | ||
} else { | ||
Rezult::Ok(true) | ||
} | ||
} | ||
|
||
/* ------------------*/ | ||
|
||
fn main() -> bool { | ||
true | ||
} |