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.
Fixes regression caused by enum and struct callpaths. (FuelLabs#4007)
## Description The issue is that struct or enum can be imported with different callpaths depending the module they are imported from. For instance we could have a struct with callpath `my_script::data_structures::SomeStruct` in a module and in another module as `my_script::eq_impls::data_structures::SomeStruct`. This makes callpaths unreliable to compare declarations. Closes FuelLabs#3998 Reopens FuelLabs#418 Disables tests multiple_enums_with_the_same_name and multiple_structs_with_the_same_name because they relied in callpath comparisons to work. ## 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). - [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: Mohammad Fawaz <[email protected]>
- Loading branch information
1 parent
2a8837d
commit 7e861e4
Showing
11 changed files
with
166 additions
and
16 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
2 changes: 1 addition & 1 deletion
2
test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/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 = "fail" | ||
category = "disabled" | ||
|
||
# check: $()x = y; | ||
# nextln: $()Mismatched types. |
2 changes: 1 addition & 1 deletion
2
.../src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/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 = "fail" | ||
category = "disabled" | ||
|
||
# check: $()x = y; | ||
# nextln: $()Mismatched types. |
13 changes: 13 additions & 0 deletions
13
...e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/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-9E94934D4E529F7D' | ||
|
||
[[package]] | ||
name = 'import_with_different_callpaths' | ||
source = 'member' | ||
dependencies = ['std'] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-9E94934D4E529F7D' | ||
dependencies = ['core'] |
8 changes: 8 additions & 0 deletions
8
...e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/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] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
license = "Apache-2.0" | ||
name = "import_with_different_callpaths" | ||
entry = "main.sw" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
25 changes: 25 additions & 0 deletions
25
...s/test_programs/should_pass/language/import_with_different_callpaths/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,25 @@ | ||
{ | ||
"configurables": [], | ||
"functions": [ | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "main", | ||
"output": { | ||
"name": "", | ||
"type": 0, | ||
"typeArguments": null | ||
} | ||
} | ||
], | ||
"loggedTypes": [], | ||
"messagesTypes": [], | ||
"types": [ | ||
{ | ||
"components": [], | ||
"type": "()", | ||
"typeId": 0, | ||
"typeParameters": null | ||
} | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
...test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.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,9 @@ | ||
library data_structures; | ||
|
||
pub struct SomeStruct<T> { | ||
a: T, | ||
} | ||
|
||
pub enum SomeEnum<T> { | ||
a: T, | ||
} |
59 changes: 59 additions & 0 deletions
59
..._tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.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,59 @@ | ||
library eq_impls; | ||
|
||
dep data_structures; | ||
|
||
use data_structures::{SomeEnum, SomeStruct}; | ||
use core::ops::Eq; | ||
|
||
impl Eq for SomeEnum<u32> { | ||
fn eq(self, other: Self) -> bool { | ||
match self { | ||
SomeEnum::a(val) => { | ||
match other { | ||
SomeEnum::a(other_val) => { | ||
val == other_val | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Eq for SomeStruct<u32> { | ||
fn eq(self, other: Self) -> bool { | ||
self.a == other.a | ||
} | ||
} | ||
|
||
impl Eq for Vec<SomeStruct<u32>> { | ||
fn eq(self, other: Self) -> bool { | ||
if self.len() != other.len() { | ||
return false; | ||
} | ||
let mut i = 0; | ||
while i < self.len() { | ||
if self.get(i).unwrap() != other.get(i).unwrap() { | ||
return false; | ||
} | ||
i += 1; | ||
} | ||
true | ||
} | ||
} | ||
|
||
impl Eq for Vec<SomeEnum<u32>> { | ||
fn eq(self, other: Self) -> bool { | ||
if self.len() != other.len() { | ||
return false; | ||
} | ||
|
||
let mut i = 0; | ||
while i < self.len() { | ||
if self.get(i).unwrap() != other.get(i).unwrap() { | ||
return false; | ||
} | ||
i += 1; | ||
} | ||
true | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/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,21 @@ | ||
script; | ||
|
||
dep eq_impls; | ||
dep data_structures; | ||
|
||
use eq_impls::*; | ||
use data_structures::*; | ||
|
||
fn main() { | ||
let mut expected = Vec::new(); | ||
expected.push(SomeEnum::a(0u32)); | ||
expected.push(SomeEnum::a(1u32)); | ||
|
||
assert(expected == expected); | ||
|
||
let mut expected = Vec::new(); | ||
expected.push(SomeStruct { a: 0u32 }); | ||
expected.push(SomeStruct { a: 1u32 }); | ||
|
||
assert(expected == expected); | ||
} |
3 changes: 3 additions & 0 deletions
3
...e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/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,3 @@ | ||
category = "run" | ||
expected_result = { action = "return", value = 0 } | ||
validate_abi = true |