-
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.
Loading status checks…
Fix module ancestor check for imports (#6671)
## Description When importing items we allow imports from ancestor modules, even if the ancestor module is declared as private. The code that performs this check was moved from `module.rs` to `root.rs` as part of #5697. During this move the current module path (i.e., the path of the destination of the import) was mistakenly replaced with the module path of the root module of the destination module. Since root modules do not have ancestors this meant that no source module was ever considered an ancestor of the destination module. This PR fixes this problem, and adds an abscure test case that shows the issue. ## Checklist - [ ] I have linked to any relevant issues. - [ ] 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) - [ ] 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. - [ ] 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). - [ ] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
1 parent
cc842e3
commit a110a95
Showing
11 changed files
with
88 additions
and
5 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
8 changes: 8 additions & 0 deletions
8
...rc/e2e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/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,8 @@ | ||
[[package]] | ||
name = "core" | ||
source = "path+from-root-044245A29CAD6C26" | ||
|
||
[[package]] | ||
name = "import_from_private_ancestor" | ||
source = "member" | ||
dependencies = ["core"] |
9 changes: 9 additions & 0 deletions
9
...rc/e2e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/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 <contact@fuel.sh>"] | ||
license = "Apache-2.0" | ||
name = "import_from_private_ancestor" | ||
entry = "main.sw" | ||
implicit-std = false | ||
|
||
[dependencies] | ||
core = { path = "../../../../../../../sway-lib-core" } |
25 changes: 25 additions & 0 deletions
25
...ests/test_programs/should_pass/language/import_from_private_ancestor/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": null, | ||
"type": "bool", | ||
"typeId": 0, | ||
"typeParameters": null | ||
} | ||
] | ||
} |
23 changes: 23 additions & 0 deletions
23
...grams/should_pass/language/import_from_private_ancestor/json_abi_oracle_new_encoding.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,23 @@ | ||
{ | ||
"concreteTypes": [ | ||
{ | ||
"concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", | ||
"type": "bool" | ||
} | ||
], | ||
"configurables": [], | ||
"encodingVersion": "1", | ||
"functions": [ | ||
{ | ||
"attributes": null, | ||
"inputs": [], | ||
"name": "main", | ||
"output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903" | ||
} | ||
], | ||
"loggedTypes": [], | ||
"messagesTypes": [], | ||
"metadataTypes": [], | ||
"programType": "script", | ||
"specVersion": "1" | ||
} |
3 changes: 3 additions & 0 deletions
3
...c/e2e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/src/foz.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,3 @@ | ||
library; | ||
|
||
mod foo; |
3 changes: 3 additions & 0 deletions
3
...e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/src/foz/foo.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,3 @@ | ||
library; | ||
|
||
mod bar; |
3 changes: 3 additions & 0 deletions
3
..._tests/test_programs/should_pass/language/import_from_private_ancestor/src/foz/foo/bar.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,3 @@ | ||
library; | ||
|
||
mod baz; |
4 changes: 4 additions & 0 deletions
4
...ts/test_programs/should_pass/language/import_from_private_ancestor/src/foz/foo/bar/baz.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,4 @@ | ||
library; | ||
|
||
// This is legal even though foo is a private module, because foo is an ancestor of the current module | ||
use ::foz::foo::*; |
3 changes: 3 additions & 0 deletions
3
.../e2e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/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,3 @@ | ||
library; | ||
|
||
mod foz; |
2 changes: 2 additions & 0 deletions
2
...rc/e2e_vm_tests/test_programs/should_pass/language/import_from_private_ancestor/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,2 @@ | ||
category = "compile" | ||
expected_warnings = 0 |