-
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.
Fix resolution of local items that shadow imported ones (#5418)
## Description Closes #5383. #5383 blocks PR #5306. ## 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. - [ ] 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
21 changed files
with
353 additions
and
44 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
13 changes: 13 additions & 0 deletions
13
.../e2e_vm_tests/test_programs/should_fail/resolve_local_items_that_shadow_imports/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-8AA4CB15A1A05A28" | ||
|
||
[[package]] | ||
name = "resolve_local_items_that_shadow_imports" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-8AA4CB15A1A05A28" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
.../e2e_vm_tests/test_programs/should_fail/resolve_local_items_that_shadow_imports/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 = "resolve_local_items_that_shadow_imports" | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
25 changes: 25 additions & 0 deletions
25
...ts/test_programs/should_fail/resolve_local_items_that_shadow_imports/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 | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
...e2e_vm_tests/test_programs/should_fail/resolve_local_items_that_shadow_imports/src/lib.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,19 @@ | ||
library; | ||
|
||
pub enum Enum { | ||
A: (), | ||
} | ||
|
||
pub struct Struct { | ||
x: u64, | ||
} | ||
|
||
pub struct PubStruct { | ||
x: u64, | ||
} | ||
|
||
pub struct GenericStruct<T> { | ||
x: T, | ||
} | ||
|
||
pub const X: u64 = 0u64; |
72 changes: 72 additions & 0 deletions
72
...2e_vm_tests/test_programs/should_fail/resolve_local_items_that_shadow_imports/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,72 @@ | ||
// This test proves that https://github.com/FuelLabs/sway/issues/5383 is fixed. | ||
|
||
script; | ||
|
||
mod lib; | ||
|
||
use lib::Enum; | ||
use lib::Struct; | ||
use lib::PubStruct; | ||
use lib::GenericStruct; | ||
|
||
enum Enum { | ||
A: (), | ||
B: (), | ||
} | ||
|
||
struct Struct { | ||
x: u64, | ||
y: u64, | ||
} | ||
|
||
impl Struct { | ||
fn use_me(self) { | ||
poke(self.x); | ||
poke(self.y); | ||
} | ||
} | ||
|
||
pub struct PubStruct { | ||
x: u64, | ||
y: u64, | ||
} | ||
|
||
impl PubStruct { | ||
fn use_me(self) { | ||
poke(self.x); | ||
poke(self.y); | ||
} | ||
} | ||
|
||
struct GenericStruct<T> { | ||
x: T, | ||
y: u64, | ||
} | ||
|
||
impl<T> GenericStruct<T> { | ||
fn use_me(self) { | ||
poke(self.x); | ||
poke(self.y); | ||
} | ||
} | ||
|
||
pub const X: bool = true; | ||
|
||
fn main() { | ||
// We must get errors for defining items multiple times, | ||
// but that should be all errors. | ||
// We shouldn't have any errors below, because the | ||
// below items will resolve to local ones. | ||
let _ = Struct { x: 0, y: 0 }; | ||
let _ = PubStruct { x: 0, y: 0 }; | ||
let _ = GenericStruct { x: 0, y: 0 }; | ||
let _ = Enum::B; | ||
let _: bool = X; | ||
|
||
Struct { x: 0, y: 0 }.use_me(); | ||
PubStruct { x: 0, y: 0 }.use_me(); | ||
GenericStruct { x: 0, y: 0 }.use_me(); | ||
poke(Enum::A); | ||
} | ||
|
||
fn poke<T>(_x: T) { } |
19 changes: 19 additions & 0 deletions
19
.../e2e_vm_tests/test_programs/should_fail/resolve_local_items_that_shadow_imports/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,19 @@ | ||
category = "fail" | ||
|
||
#check: $()error | ||
#check: $()enum Enum { | ||
#nextln: $()Name "Enum" is defined multiple times. | ||
|
||
#check: $()error | ||
#check: $()struct Struct { | ||
#nextln: $()Name "Struct" is defined multiple times. | ||
|
||
#check: $()error | ||
#check: $()pub struct PubStruct { | ||
#nextln: $()Name "PubStruct" is defined multiple times. | ||
|
||
#check: $()error | ||
#check: $()struct GenericStruct<T> { | ||
#nextln: $()Name "GenericStruct" is defined multiple times. | ||
|
||
#not: $()error |
5 changes: 0 additions & 5 deletions
5
test/src/e2e_vm_tests/test_programs/should_pass/language/diverging_exprs/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
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
13 changes: 13 additions & 0 deletions
13
.../e2e_vm_tests/test_programs/should_pass/resolve_local_items_that_shadow_imports/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-8AA4CB15A1A05A28" | ||
|
||
[[package]] | ||
name = "resolve_local_items_that_shadow_imports" | ||
source = "member" | ||
dependencies = ["std"] | ||
|
||
[[package]] | ||
name = "std" | ||
source = "path+from-root-8AA4CB15A1A05A28" | ||
dependencies = ["core"] |
8 changes: 8 additions & 0 deletions
8
.../e2e_vm_tests/test_programs/should_pass/resolve_local_items_that_shadow_imports/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 = "resolve_local_items_that_shadow_imports" | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
25 changes: 25 additions & 0 deletions
25
...ts/test_programs/should_pass/resolve_local_items_that_shadow_imports/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 | ||
} | ||
] | ||
} |
19 changes: 19 additions & 0 deletions
19
...e2e_vm_tests/test_programs/should_pass/resolve_local_items_that_shadow_imports/src/lib.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,19 @@ | ||
library; | ||
|
||
pub enum Enum { | ||
A: (), | ||
} | ||
|
||
pub struct Struct { | ||
x: u64, | ||
} | ||
|
||
pub struct PubStruct { | ||
x: u64, | ||
} | ||
|
||
pub struct GenericStruct<T> { | ||
x: T, | ||
} | ||
|
||
pub const X: u64 = 0u64; |
Oops, something went wrong.