From 701af2008088fe2629f18cf92afcf677bd4d5212 Mon Sep 17 00:00:00 2001 From: jjcnn <38888011+jjcnn@users.noreply.github.com> Date: Mon, 15 Jul 2024 13:17:58 +0200 Subject: [PATCH] Feature: Reexport using `pub use` (#6116) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes #3113 . Closes #2767 as Won't Fix, since one must use `pub use` to reexport items. This PR Introduce reexports through the use of `pub use`. The implementation now keeps track of the visibility of a `use` statement, and that visibility is in turn taken into account when items are imported from the module where the `use` statement resides. This feature allows `std::prelude` and `core::prelude` to be handled correctly, instead of the special-case handling that we have been using so far. The method `star_import_with_reexports` has therefore been merged with `star_import`, and the `prelude.sw` files have accordingly been changed to use `pub use` instead of `use`. Note that `sway-lib-std/lib.sw` has a spurious import of `core::*`, which has no effect, so I have removed that import. This change also allows us to remove a hacky solution in `lexical_scope.rs`. The hack was introduced because the special-case handling of preludes meant that the preludes would contain multiple copies of the same `std` and `core` items. Now that we no longer need to treat the preludes specially, we can remove the hack. I have gone a little overboard in adding tests, partly because I wanted to make sure I hadn't missed some corner cases, but also because our tests of the import logic has poor code coverage. I have found the following issues that I don't think belongs in this PR, but which need to be handled at some point: - Path resolution is broken. The tests `should_pass/language/reexport/simple_path_access` and `should_fail/language/reexport/simple_path_access` are supposed to test that you can access reexported using a path into the reexporting module, i.e., without importing them using a `use` statement. Both tests are disabled because path resolution is broken. I plan to fix that as part of #5498 . A simlar problem exists in the test `should_pass/language/reexport/reexport_paths` where an item is imported via `std::prelude`. - There is an issue with the import and reexport of enum variants, which is illustrated in `should_pass/language/reexport/reexport_paths_external_lib`. In short, `pub use ext_3_lib::Items3_Variants::U` elevates the name `U` to the top-level namespace in a module, and this makes `U` inaccessible as a variant of `Items3_Variants`. I'm not sure how this is supposed to work, but since it's related to all imports whether they are reexported or not I have left it as a separate issue #6233 . - Aliasing of enum variants (`use lib::Enum::X as MyX`) doesn't work properly. In some cases `MyX` is available in the way you would expect, and in other cases it is not, and sometimes it is available but not recognized as being a variant of `lib::Enum`. The test `should_pass/language/reexport/aliases` has a number of tests of these types of things. #6123 tracks the issue. - Aliased traits are not handled correctly by the dead code analysis. The test `should_pass/language/reexport/aliases` generates warnings about unimplemented traits that are actually implemented, but since they are aliased in imports the DCA doesn't catch them. #6234 tracks the issue. Re. documentation: The whole import system is completely undocumented in the Sway book, and I plan to write up a draft how it works when I'm done fixing (the majority of) the many issue we have there. At the very least I'd like to postpone the documentation efforts until path resolution works correctly, since that is key to how the import system works. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] 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) - [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: Joshua Batty Co-authored-by: João Matos --- forc-pkg/src/pkg.rs | 6 +- sway-core/src/language/call_path.rs | 2 +- .../src/language/parsed/use_statement.rs | 5 +- .../src/semantic_analysis/ast_node/mod.rs | 49 +- .../semantic_analysis/collection_context.rs | 14 +- .../namespace/lexical_scope.rs | 61 +- .../src/semantic_analysis/namespace/root.rs | 785 +++++++++--------- .../semantic_analysis/type_check_context.rs | 14 +- .../to_parsed_lang/convert_parse_tree.rs | 23 +- sway-error/src/convert_parse_tree_error.rs | 3 - sway-lib-core/src/prelude.sw | 18 +- sway-lib-std/src/lib.sw | 2 - sway-lib-std/src/prelude.sw | 34 +- sway-lsp/tests/fixtures/tokens/abi/Forc.toml | 5 +- .../tests/fixtures/tokens/consts/Forc.toml | 5 +- .../tests/fixtures/tokens/fields/Forc.toml | 5 +- .../tests/fixtures/tokens/matches/Forc.toml | 5 +- .../tests/fixtures/tokens/paths/Forc.toml | 5 +- .../tests/fixtures/tokens/structs/Forc.toml | 5 +- .../tests/fixtures/tokens/turbofish/Forc.toml | 5 +- .../tests/fixtures/tokens/variables/Forc.toml | 5 +- sway-lsp/tests/lib.rs | 156 ++-- .../sway-lib-std-assert/src/prelude.sw | 6 +- .../sway-lib-std-conversions/src/prelude.sw | 20 +- .../sway-lib-std-option-result/src/prelude.sw | 10 +- .../sway-lib-std-vec/src/prelude.sw | 14 +- .../language/reexport/aliases/Forc.lock | 13 + .../language/reexport/aliases/Forc.toml | 9 + .../reexport/aliases/json_abi_oracle.json | 25 + .../aliases/json_abi_oracle_new_encoding.json | 26 + .../language/reexport/aliases/src/items_1.sw | 25 + .../language/reexport/aliases/src/items_2.sw | 25 + .../language/reexport/aliases/src/items_3.sw | 25 + .../language/reexport/aliases/src/items_4.sw | 25 + .../language/reexport/aliases/src/items_5.sw | 5 + .../language/reexport/aliases/src/lib_1.sw | 14 + .../language/reexport/aliases/src/lib_2.sw | 14 + .../language/reexport/aliases/src/lib_3.sw | 14 + .../language/reexport/aliases/src/lib_4_1.sw | 14 + .../language/reexport/aliases/src/lib_4_2.sw | 14 + .../language/reexport/aliases/src/lib_5_1.sw | 3 + .../language/reexport/aliases/src/lib_5_2.sw | 3 + .../language/reexport/aliases/src/main.sw | 20 + .../language/reexport/aliases/src/tests.sw | 184 ++++ .../language/reexport/aliases/test.toml | 188 +++++ .../Forc.lock | 13 + .../Forc.toml | 9 + .../json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../src/items_1.sw | 25 + .../src/lib_1_1.sw | 4 + .../src/lib_1_2.sw | 4 + .../src/main.sw | 11 + .../src/tests.sw | 88 ++ .../test.toml | 31 + .../shadowing_in_reexporting_module/Forc.lock | 13 + .../shadowing_in_reexporting_module/Forc.toml | 9 + .../json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../src/items_1.sw | 20 + .../src/items_2_1.sw | 20 + .../src/items_2_2.sw | 20 + .../src/items_3_1.sw | 25 + .../src/items_4_1.sw | 25 + .../src/items_4_2.sw | 25 + .../src/items_4_3.sw | 6 + .../src/items_4_4.sw | 6 + .../src/lib_1.sw | 22 + .../src/lib_2.sw | 9 + .../src/lib_3.sw | 28 + .../src/lib_4.sw | 17 + .../src/main.sw | 20 + .../src/tests.sw | 273 ++++++ .../shadowing_in_reexporting_module/test.toml | 191 +++++ .../reexport/simple_glob_import/Forc.lock | 13 + .../reexport/simple_glob_import/Forc.toml | 9 + .../simple_glob_import/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_glob_import/src/items_1.sw | 25 + .../simple_glob_import/src/items_2.sw | 25 + .../reexport/simple_glob_import/src/lib_1.sw | 14 + .../reexport/simple_glob_import/src/lib_2.sw | 5 + .../reexport/simple_glob_import/src/main.sw | 12 + .../reexport/simple_glob_import/src/tests.sw | 126 +++ .../reexport/simple_glob_import/test.toml | 129 +++ .../reexport/simple_item_import/Forc.lock | 13 + .../reexport/simple_item_import/Forc.toml | 9 + .../simple_item_import/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_item_import/src/items_1.sw | 25 + .../simple_item_import/src/items_2.sw | 25 + .../simple_item_import/src/items_3.sw | 6 + .../reexport/simple_item_import/src/lib_1.sw | 14 + .../reexport/simple_item_import/src/lib_2.sw | 5 + .../reexport/simple_item_import/src/lib_3.sw | 3 + .../reexport/simple_item_import/src/main.sw | 12 + .../reexport/simple_item_import/src/tests.sw | 158 ++++ .../reexport/simple_item_import/test.toml | 91 ++ .../reexport/simple_path_access/Forc.lock | 13 + .../reexport/simple_path_access/Forc.toml | 9 + .../simple_path_access/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_path_access/src/items_1.sw | 25 + .../simple_path_access/src/items_2.sw | 25 + .../reexport/simple_path_access/src/lib_1.sw | 14 + .../reexport/simple_path_access/src/lib_2.sw | 5 + .../reexport/simple_path_access/src/main.sw | 12 + .../reexport/simple_path_access/src/tests.sw | 96 +++ .../reexport/simple_path_access/test.toml | 4 + .../language/reexport/aliases/Forc.lock | 13 + .../language/reexport/aliases/Forc.toml | 9 + .../reexport/aliases/json_abi_oracle.json | 25 + .../aliases/json_abi_oracle_new_encoding.json | 26 + .../language/reexport/aliases/src/items_1.sw | 25 + .../language/reexport/aliases/src/items_2.sw | 25 + .../language/reexport/aliases/src/items_3.sw | 25 + .../language/reexport/aliases/src/items_4.sw | 21 + .../language/reexport/aliases/src/lib_1.sw | 14 + .../language/reexport/aliases/src/lib_2.sw | 14 + .../language/reexport/aliases/src/lib_3_1.sw | 14 + .../language/reexport/aliases/src/lib_3_2.sw | 14 + .../language/reexport/aliases/src/lib_4_1.sw | 12 + .../language/reexport/aliases/src/lib_4_2.sw | 12 + .../language/reexport/aliases/src/main.sw | 18 + .../language/reexport/aliases/src/tests.sw | 253 ++++++ .../language/reexport/aliases/test.toml | 5 + .../Forc.lock | 13 + .../Forc.toml | 9 + .../json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../src/items_1.sw | 25 + .../src/items_2.sw | 25 + .../src/items_3.sw | 25 + .../src/items_4.sw | 25 + .../src/lib_1_1.sw | 14 + .../src/lib_1_2.sw | 14 + .../src/lib_2_1.sw | 5 + .../src/lib_2_2.sw | 5 + .../src/lib_3_1.sw | 5 + .../src/lib_3_2.sw | 14 + .../src/lib_4_1.sw | 14 + .../src/lib_4_2.sw | 5 + .../src/main.sw | 20 + .../src/tests.sw | 243 ++++++ .../test.toml | 5 + .../reexport/reexport_paths/Forc.lock | 13 + .../reexport/reexport_paths/Forc.toml | 9 + .../reexport_paths/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../reexport/reexport_paths/src/items_1.sw | 25 + .../reexport/reexport_paths/src/lib_1_1.sw | 4 + .../reexport/reexport_paths/src/lib_1_2.sw | 4 + .../reexport/reexport_paths/src/lib_2.sw | 3 + .../reexport/reexport_paths/src/lib_3_1.sw | 4 + .../reexport/reexport_paths/src/lib_3_2.sw | 3 + .../reexport/reexport_paths/src/lib_4.sw | 3 + .../reexport/reexport_paths/src/lib_5.sw | 3 + .../reexport/reexport_paths/src/lib_6_1.sw | 3 + .../reexport/reexport_paths/src/lib_6_2.sw | 3 + .../reexport/reexport_paths/src/main.sw | 18 + .../reexport/reexport_paths/src/tests.sw | 140 ++++ .../reexport/reexport_paths/test.toml | 5 + .../reexport_paths_external_lib/Forc.lock | 76 ++ .../reexport_paths_external_lib/Forc.toml | 14 + .../ext_1_items/Forc.toml | 6 + .../ext_1_items/src/lib.sw | 25 + .../ext_1_lib/Forc.toml | 9 + .../ext_1_lib/src/lib.sw | 14 + .../ext_2_items/Forc.toml | 6 + .../ext_2_items/src/lib.sw | 25 + .../ext_2_lib/Forc.toml | 9 + .../ext_2_lib/src/lib.sw | 4 + .../ext_3_items/Forc.toml | 6 + .../ext_3_items/src/lib.sw | 25 + .../ext_3_lib/Forc.toml | 9 + .../ext_3_lib/src/lib.sw | 14 + .../ext_4_items/Forc.toml | 6 + .../ext_4_items/src/lib.sw | 25 + .../ext_4_lib/Forc.toml | 9 + .../ext_4_lib/src/lib.sw | 4 + .../ext_5_1_lib/Forc.toml | 9 + .../ext_5_1_lib/src/lib.sw | 4 + .../ext_5_2_lib/Forc.toml | 9 + .../ext_5_2_lib/src/lib.sw | 4 + .../ext_5_items/Forc.toml | 6 + .../ext_5_items/src/lib.sw | 25 + .../json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../program/Forc.toml | 20 + .../program/src/main.sw | 7 + .../program/src/tests.sw | 310 +++++++ .../reexport_paths_external_lib/test.toml | 2 + .../shadowing_in_reexporting_module/Forc.lock | 13 + .../shadowing_in_reexporting_module/Forc.toml | 9 + .../json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../src/items_1.sw | 20 + .../src/items_2_1.sw | 20 + .../src/items_2_2.sw | 20 + .../src/items_3_1.sw | 25 + .../src/items_4_1.sw | 25 + .../src/items_4_2.sw | 25 + .../src/items_4_3.sw | 6 + .../src/items_4_4.sw | 6 + .../src/lib_1.sw | 22 + .../src/lib_2.sw | 9 + .../src/lib_3.sw | 28 + .../src/lib_4.sw | 17 + .../src/main.sw | 20 + .../src/tests.sw | 262 ++++++ .../shadowing_in_reexporting_module/test.toml | 5 + .../reexport/simple_glob_import/Forc.lock | 13 + .../reexport/simple_glob_import/Forc.toml | 9 + .../simple_glob_import/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_glob_import/src/items_1.sw | 25 + .../simple_glob_import/src/items_2.sw | 25 + .../reexport/simple_glob_import/src/lib_1.sw | 14 + .../reexport/simple_glob_import/src/lib_2.sw | 5 + .../reexport/simple_glob_import/src/main.sw | 12 + .../reexport/simple_glob_import/src/tests.sw | 126 +++ .../reexport/simple_glob_import/test.toml | 5 + .../reexport/simple_item_import/Forc.lock | 13 + .../reexport/simple_item_import/Forc.toml | 9 + .../simple_item_import/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_item_import/src/items_1.sw | 25 + .../simple_item_import/src/items_2.sw | 25 + .../reexport/simple_item_import/src/lib_1.sw | 14 + .../reexport/simple_item_import/src/lib_2.sw | 5 + .../reexport/simple_item_import/src/main.sw | 12 + .../reexport/simple_item_import/src/tests.sw | 142 ++++ .../reexport/simple_item_import/test.toml | 5 + .../reexport/simple_path_access/Forc.lock | 13 + .../reexport/simple_path_access/Forc.toml | 9 + .../simple_path_access/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../simple_path_access/src/items_1.sw | 25 + .../simple_path_access/src/items_2.sw | 25 + .../reexport/simple_path_access/src/lib_1.sw | 14 + .../reexport/simple_path_access/src/lib_2.sw | 5 + .../reexport/simple_path_access/src/main.sw | 12 + .../reexport/simple_path_access/src/tests.sw | 97 +++ .../reexport/simple_path_access/test.toml | 5 + .../language/reexport/visibility/Forc.lock | 13 + .../language/reexport/visibility/Forc.toml | 9 + .../reexport/visibility/json_abi_oracle.json | 25 + .../json_abi_oracle_new_encoding.json | 26 + .../reexport/visibility/src/items_1.sw | 25 + .../reexport/visibility/src/items_2.sw | 25 + .../reexport/visibility/src/lib_1_1.sw | 14 + .../reexport/visibility/src/lib_1_2.sw | 14 + .../reexport/visibility/src/lib_2_1.sw | 14 + .../reexport/visibility/src/lib_2_2.sw | 14 + .../language/reexport/visibility/src/main.sw | 14 + .../language/reexport/visibility/src/tests.sw | 128 +++ .../language/reexport/visibility/test.toml | 5 + 257 files changed, 7208 insertions(+), 608 deletions(-) create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_3.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_4.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_5.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_3.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_3.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_4.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_4.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/items_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_4.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_5.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/src/lib.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/src/lib.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle_new_encoding.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/tests.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/test.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.lock create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.toml create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle.json create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle_new_encoding.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_1.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_2.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_1.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_2.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/tests.sw create mode 100755 test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/test.toml diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 7092d3e63ef..c7e6439e300 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -1665,20 +1665,22 @@ pub fn dependency_namespace( let mut root = namespace::Root::from(root_module); if core_added { - let _ = root.star_import_with_reexports( + let _ = root.star_import( &Handler::default(), engines, &[CORE, PRELUDE].map(|s| Ident::new_no_span(s.into())), &[], + Visibility::Private, ); } if has_std_dep(graph, node) { - let _ = root.star_import_with_reexports( + let _ = root.star_import( &Handler::default(), engines, &[STD, PRELUDE].map(|s| Ident::new_no_span(s.into())), &[], + Visibility::Private, ); } diff --git a/sway-core/src/language/call_path.rs b/sway-core/src/language/call_path.rs index d0f993438b8..e71cef0aa93 100644 --- a/sway-core/src/language/call_path.rs +++ b/sway-core/src/language/call_path.rs @@ -369,7 +369,7 @@ impl CallPath { if let Some(mod_path) = namespace.program_id(engines).read(engines, |m| { if m.current_items().symbols().contains_key(&self.suffix) { None - } else if let Some((_, path, _)) = m + } else if let Some((_, path, _, _)) = m .current_items() .use_item_synonyms .get(&self.suffix) diff --git a/sway-core/src/language/parsed/use_statement.rs b/sway-core/src/language/parsed/use_statement.rs index 9734d4f8bfc..ceda688d75f 100644 --- a/sway-core/src/language/parsed/use_statement.rs +++ b/sway-core/src/language/parsed/use_statement.rs @@ -1,4 +1,4 @@ -use crate::parsed::Span; +use crate::{language::Visibility, parsed::Span}; use sway_types::ident::Ident; #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -17,5 +17,8 @@ pub struct UseStatement { // If `is_absolute` is true, then this use statement is an absolute path from // the project root namespace. If not, then it is relative to the current namespace. pub is_absolute: bool, + // If `reexport` is Visibility::Public, then this use statement reexports its imported binding. + // If not, then the import binding is private to the importing module. + pub reexport: Visibility, pub alias: Option, } diff --git a/sway-core/src/semantic_analysis/ast_node/mod.rs b/sway-core/src/semantic_analysis/ast_node/mod.rs index 1bb142e8cf1..aab6354cfc0 100644 --- a/sway-core/src/semantic_analysis/ast_node/mod.rs +++ b/sway-core/src/semantic_analysis/ast_node/mod.rs @@ -167,7 +167,7 @@ fn collect_use_statement( ImportType::Star => { // try a standard starimport first let star_import_handler = Handler::default(); - let import = ctx.star_import(&star_import_handler, engines, &path); + let import = ctx.star_import(&star_import_handler, engines, &path, stmt.reexport); if import.is_ok() { handler.append(star_import_handler); import @@ -175,8 +175,13 @@ fn collect_use_statement( // if it doesn't work it could be an enum star import if let Some((enum_name, path)) = path.split_last() { let variant_import_handler = Handler::default(); - let variant_import = - ctx.variant_star_import(&variant_import_handler, engines, path, enum_name); + let variant_import = ctx.variant_star_import( + &variant_import_handler, + engines, + path, + enum_name, + stmt.reexport, + ); if variant_import.is_ok() { handler.append(variant_import_handler); variant_import @@ -190,12 +195,20 @@ fn collect_use_statement( } } } - ImportType::SelfImport(_) => ctx.self_import(handler, engines, &path, stmt.alias.clone()), + ImportType::SelfImport(_) => { + ctx.self_import(handler, engines, &path, stmt.alias.clone(), stmt.reexport) + } ImportType::Item(ref s) => { // try a standard item import first let item_import_handler = Handler::default(); - let import = - ctx.item_import(&item_import_handler, engines, &path, s, stmt.alias.clone()); + let import = ctx.item_import( + &item_import_handler, + engines, + &path, + s, + stmt.alias.clone(), + stmt.reexport, + ); if import.is_ok() { handler.append(item_import_handler); @@ -211,6 +224,7 @@ fn collect_use_statement( enum_name, s, stmt.alias.clone(), + stmt.reexport, ); if variant_import.is_ok() { handler.append(variant_import_handler); @@ -252,7 +266,7 @@ fn handle_use_statement( ImportType::Star => { // try a standard starimport first let star_import_handler = Handler::default(); - let import = ctx.star_import(&star_import_handler, &path); + let import = ctx.star_import(&star_import_handler, &path, stmt.reexport); if import.is_ok() { handler.append(star_import_handler); import @@ -260,8 +274,12 @@ fn handle_use_statement( // if it doesn't work it could be an enum star import if let Some((enum_name, path)) = path.split_last() { let variant_import_handler = Handler::default(); - let variant_import = - ctx.variant_star_import(&variant_import_handler, path, enum_name); + let variant_import = ctx.variant_star_import( + &variant_import_handler, + path, + enum_name, + stmt.reexport, + ); if variant_import.is_ok() { handler.append(variant_import_handler); variant_import @@ -275,11 +293,19 @@ fn handle_use_statement( } } } - ImportType::SelfImport(_) => ctx.self_import(handler, &path, stmt.alias.clone()), + ImportType::SelfImport(_) => { + ctx.self_import(handler, &path, stmt.alias.clone(), stmt.reexport) + } ImportType::Item(ref s) => { // try a standard item import first let item_import_handler = Handler::default(); - let import = ctx.item_import(&item_import_handler, &path, s, stmt.alias.clone()); + let import = ctx.item_import( + &item_import_handler, + &path, + s, + stmt.alias.clone(), + stmt.reexport, + ); if import.is_ok() { handler.append(item_import_handler); @@ -294,6 +320,7 @@ fn handle_use_statement( enum_name, s, stmt.alias.clone(), + stmt.reexport, ); if variant_import.is_ok() { handler.append(variant_import_handler); diff --git a/sway-core/src/semantic_analysis/collection_context.rs b/sway-core/src/semantic_analysis/collection_context.rs index 9a59bf32072..8fb8937fc47 100644 --- a/sway-core/src/semantic_analysis/collection_context.rs +++ b/sway-core/src/semantic_analysis/collection_context.rs @@ -108,11 +108,12 @@ impl SymbolCollectionContext { handler: &Handler, engines: &Engines, src: &ModulePath, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .star_import(handler, engines, src, &mod_path) + .star_import(handler, engines, src, &mod_path, visibility) } /// Short-hand for performing a [Module::variant_star_import] with `mod_path` as the destination. @@ -122,11 +123,12 @@ impl SymbolCollectionContext { engines: &Engines, src: &ModulePath, enum_name: &Ident, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .variant_star_import(handler, engines, src, &mod_path, enum_name) + .variant_star_import(handler, engines, src, &mod_path, enum_name, visibility) } /// Short-hand for performing a [Module::self_import] with `mod_path` as the destination. @@ -136,11 +138,12 @@ impl SymbolCollectionContext { engines: &Engines, src: &ModulePath, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .self_import(handler, engines, src, &mod_path, alias) + .self_import(handler, engines, src, &mod_path, alias, visibility) } /// Short-hand for performing a [Module::item_import] with `mod_path` as the destination. @@ -151,11 +154,12 @@ impl SymbolCollectionContext { src: &ModulePath, item: &Ident, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .item_import(handler, engines, src, item, &mod_path, alias) + .item_import(handler, engines, src, item, &mod_path, alias, visibility) } /// Short-hand for performing a [Module::variant_import] with `mod_path` as the destination. @@ -168,6 +172,7 @@ impl SymbolCollectionContext { enum_name: &Ident, variant_name: &Ident, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let mod_path = self.namespace().mod_path.clone(); self.namespace_mut().root.variant_import( @@ -178,6 +183,7 @@ impl SymbolCollectionContext { variant_name, &mod_path, alias, + visibility, ) } } diff --git a/sway-core/src/semantic_analysis/namespace/lexical_scope.rs b/sway-core/src/semantic_analysis/namespace/lexical_scope.rs index 6789146b722..e82bf24846c 100644 --- a/sway-core/src/semantic_analysis/namespace/lexical_scope.rs +++ b/sway-core/src/semantic_analysis/namespace/lexical_scope.rs @@ -4,7 +4,7 @@ use crate::{ language::{ parsed::{Declaration, FunctionDeclaration}, ty::{self, StructAccessInfo, TyDecl, TyStorageDecl}, - CallPath, + CallPath, Visibility, }, namespace::*, semantic_analysis::{ast_node::ConstShadowingMode, GenericShadowingMode}, @@ -36,10 +36,20 @@ impl ResolvedFunctionDecl { } pub(super) type SymbolMap = im::OrdMap; + type SourceIdent = Ident; -pub(super) type GlobSynonyms = im::HashMap>; -pub(super) type ItemSynonyms = - im::HashMap, ModulePathBuf, ResolvedDeclaration)>; + +pub(super) type GlobSynonyms = + im::HashMap>; +pub(super) type ItemSynonyms = im::HashMap< + Ident, + ( + Option, + ModulePathBuf, + ResolvedDeclaration, + Visibility, + ), +>; /// Represents a lexical scope integer-based identifier, which can be used to reference /// specific a lexical scope. @@ -464,7 +474,7 @@ impl Items { ); } - if let Some((ident, (imported_ident, _, decl))) = + if let Some((ident, (imported_ident, _, decl, _))) = self.use_item_synonyms.get_key_value(&name) { append_shadowing_error( @@ -494,43 +504,30 @@ impl Items { symbol: Ident, src_path: ModulePathBuf, decl: &ResolvedDeclaration, + visibility: Visibility, ) { if let Some(cur_decls) = self.use_glob_synonyms.get_mut(&symbol) { // Name already bound. Check if the decl is already imported let ctx = PartialEqWithEnginesContext::new(engines); - match cur_decls.iter().position(|(cur_path, cur_decl)| { - cur_decl.eq(decl, &ctx) - // For some reason the equality check is not sufficient. In some cases items that - // are actually identical fail the eq check, so we have to add heuristics for these - // cases. - // - // These edge occur because core and std preludes are not reexported correctly. Once - // reexports are implemented we can handle the preludes correctly, and then these - // edge cases should go away. - // See https://github.com/FuelLabs/sway/issues/3113 - // - // As a heuristic we replace any bindings from std and core if the new binding is - // also from std or core. This does not work if the user has declared an item with - // the same name as an item in one of the preludes, but this is an edge case that we - // will have to live with for now. - || ((cur_path[0].as_str() == "core" || cur_path[0].as_str() == "std") - && (src_path[0].as_str() == "core" || src_path[0].as_str() == "std")) - }) { - Some(index) => { - // The name is already bound to this decl, but - // we need to replace the binding to make the paths work out. - // This appears to be an issue with the core prelude, and will probably no - // longer be necessary once reexports are implemented: - // https://github.com/FuelLabs/sway/issues/3113 - cur_decls[index] = (src_path.to_vec(), decl.clone()); + match cur_decls + .iter() + .position(|(_cur_path, cur_decl, _cur_visibility)| cur_decl.eq(decl, &ctx)) + { + Some(index) if matches!(visibility, Visibility::Public) => { + // The name is already bound to this decl. If the new symbol is more visible + // than the old one, then replace the old one. + cur_decls[index] = (src_path.to_vec(), decl.clone(), visibility); + } + Some(_) => { + // Same binding as the existing one. Do nothing. } None => { // New decl for this name. Add it to the end - cur_decls.push((src_path.to_vec(), decl.clone())); + cur_decls.push((src_path.to_vec(), decl.clone(), visibility)); } } } else { - let new_vec = vec![(src_path.to_vec(), decl.clone())]; + let new_vec = vec![(src_path.to_vec(), decl.clone(), visibility)]; self.use_glob_synonyms.insert(symbol, new_vec); } } diff --git a/sway-core/src/semantic_analysis/namespace/root.rs b/sway-core/src/semantic_analysis/namespace/root.rs index 7f016a9885c..960909134ef 100644 --- a/sway-core/src/semantic_analysis/namespace/root.rs +++ b/sway-core/src/semantic_analysis/namespace/root.rs @@ -11,7 +11,7 @@ use crate::{ ty::{self, TyDecl, TyTraitItem}, CallPath, Visibility, }, - namespace::ModulePath, + namespace::{ModulePath, ModulePathBuf}, TypeId, TypeInfo, }; use sway_error::{ @@ -62,6 +62,13 @@ impl PartialEqWithEngines for ResolvedDeclaration { } impl ResolvedDeclaration { + pub fn is_typed(&self) -> bool { + match self { + ResolvedDeclaration::Parsed(_) => false, + ResolvedDeclaration::Typed(_) => true, + } + } + pub fn expect_parsed(self) -> Declaration { match self { ResolvedDeclaration::Parsed(decl) => decl, @@ -142,38 +149,89 @@ impl Root { /// This is used when an import path contains an asterisk. /// /// Paths are assumed to be absolute. - pub(crate) fn star_import( + pub fn star_import( &mut self, handler: &Handler, engines: &Engines, src: &ModulePath, dst: &ModulePath, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { self.check_module_privacy(handler, engines, src)?; let src_mod = self.module.lookup_submodule(handler, engines, src)?; - let implemented_traits = src_mod.current_items().implemented_traits.clone(); - let mut symbols_and_decls = vec![]; + + let mut decls_and_item_imports = vec![]; + + let get_path = |mod_path: Vec| { + let mut is_external = false; + if let Some(submodule) = src_mod.submodule(engines, &[mod_path[0].clone()]) { + is_external = submodule.is_external + }; + + let mut path = src[..1].to_vec(); + if is_external { + path = mod_path; + } else { + path.extend(mod_path); + } + + path + }; + + // Collect all items declared in the source module for (symbol, decl) in src_mod.current_items().symbols.iter() { if is_ancestor(src, dst) || decl.visibility(engines).is_public() { - symbols_and_decls.push((symbol.clone(), decl.clone())); + decls_and_item_imports.push((symbol.clone(), decl.clone(), src.to_vec())); + } + } + // Collect those item-imported items that the source module reexports + // These live in the same namespace as local declarations, so no shadowing is possible + for (symbol, (_, path, decl, src_visibility)) in + src_mod.current_items().use_item_synonyms.iter() + { + if src_visibility.is_public() { + decls_and_item_imports.push((symbol.clone(), decl.clone(), get_path(path.clone()))) } } + // Collect those glob-imported items that the source module reexports. These may be shadowed + // by local declarations and item imports in the source module, so they are treated + // separately. + let mut glob_imports = vec![]; + for (symbol, bindings) in src_mod.current_items().use_glob_synonyms.iter() { + // Ignore if the symbol is shadowed by a local declaration or an item import in the source module + if !decls_and_item_imports + .iter() + .any(|(other_symbol, _, _)| symbol == other_symbol) + { + for (path, decl, src_visibility) in bindings.iter() { + if src_visibility.is_public() { + glob_imports.push((symbol.clone(), decl.clone(), get_path(path.clone()))) + } + } + } + } + + let implemented_traits = src_mod.current_items().implemented_traits.clone(); let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; dst_mod .current_items_mut() .implemented_traits .extend(implemented_traits, engines); - symbols_and_decls.iter().for_each(|(symbol, decl)| { - dst_mod.current_items_mut().insert_glob_use_symbol( - engines, - symbol.clone(), - src.to_vec(), - decl, - ) - }); + decls_and_item_imports + .iter() + .chain(glob_imports.iter()) + .for_each(|(symbol, decl, path)| { + dst_mod.current_items_mut().insert_glob_use_symbol( + engines, + symbol.clone(), + path.clone(), + decl, + visibility, + ) + }); Ok(()) } @@ -189,9 +247,77 @@ impl Root { src: &ModulePath, dst: &ModulePath, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let (last_item, src) = src.split_last().expect("guaranteed by grammar"); - self.item_import(handler, engines, src, last_item, dst, alias) + self.item_import(handler, engines, src, last_item, dst, alias, visibility) + } + + fn item_lookup( + &self, + handler: &Handler, + engines: &Engines, + item: &Ident, + src: &ModulePath, + dst: &ModulePath, + ) -> Result<(ResolvedDeclaration, ModulePathBuf), ErrorEmitted> { + let src_mod = self.module.lookup_submodule(handler, engines, src)?; + let src_items = src_mod.current_items(); + + let (decl, path, src_visibility) = if let Some(decl) = src_items.symbols.get(item) { + let visibility = if is_ancestor(src, dst) { + Visibility::Public + } else { + decl.visibility(engines) + }; + (decl.clone(), src.to_vec(), visibility) + } else if let Some((_, path, decl, reexport)) = src_items.use_item_synonyms.get(item) { + (decl.clone(), path.clone(), *reexport) + } else if let Some(decls) = src_items.use_glob_synonyms.get(item) { + if decls.len() == 1 { + let (path, decl, reexport) = &decls[0]; + (decl.clone(), path.clone(), *reexport) + } else if decls.is_empty() { + return Err(handler.emit_err(CompileError::Internal( + "The name {symbol} was bound in a star import, but no corresponding module paths were found", + item.span(), + ))); + } else { + return Err(handler.emit_err(CompileError::SymbolWithMultipleBindings { + name: item.clone(), + paths: decls + .iter() + .map(|(path, decl, _)| { + let mut path_strs = path.iter().map(|x| x.as_str()).collect::>(); + // Add the enum name to the path if the decl is an enum variant. + if let TyDecl::EnumVariantDecl(ty::EnumVariantDecl { + enum_ref, .. + }) = decl.expect_typed_ref() + { + path_strs.push(enum_ref.name().as_str()) + }; + path_strs.join("::") + }) + .collect(), + span: item.span(), + })); + } + } else { + // Symbol not found + return Err(handler.emit_err(CompileError::SymbolNotFound { + name: item.clone(), + span: item.span(), + })); + }; + + if !src_visibility.is_public() { + handler.emit_err(CompileError::ImportPrivateSymbol { + name: item.clone(), + span: item.span(), + }); + } + + Ok((decl, path)) } /// Pull a single `item` from the given `src` module and import it into the `dst` module. @@ -206,89 +332,68 @@ impl Root { item: &Ident, dst: &ModulePath, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { self.check_module_privacy(handler, engines, src)?; - let src_mod = self.module.lookup_submodule(handler, engines, src)?; - let mut impls_to_insert = TraitMap::default(); - match src_mod.current_items().symbols.get(item).cloned() { - Some(decl) => { - if !decl.visibility(engines).is_public() && !is_ancestor(src, dst) { - handler.emit_err(CompileError::ImportPrivateSymbol { - name: item.clone(), - span: item.span(), - }); - } - // We only handle trait imports when handling typed declarations, - // that is, when performing type-checking, and not when collecting. - // Update this once the type system is updated to refer to parsed - // declarations. - let handle_trait_import = match decl { - ResolvedDeclaration::Parsed(_) => false, - ResolvedDeclaration::Typed(_) => true, - }; - - if handle_trait_import { - // if this is an enum or struct or function, import its implementations - if let Ok(type_id) = decl.return_type(&Handler::default(), engines) { - impls_to_insert.extend( - src_mod - .current_items() - .implemented_traits - .filter_by_type_item_import(type_id, engines), - engines, - ); - } - // if this is a trait, import its implementations - let decl_span = decl.span(engines); - if decl.is_trait() { - // TODO: we only import local impls from the source namespace - // this is okay for now but we'll need to device some mechanism to collect all available trait impls - impls_to_insert.extend( - src_mod - .current_items() - .implemented_traits - .filter_by_trait_decl_span(decl_span), - engines, - ); - } - } + let (decl, path) = self.item_lookup(handler, engines, item, src, dst)?; - // no matter what, import it this way though. - let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; - let check_name_clash = |name| { - if let Some((_, _, _)) = dst_mod.current_items().use_item_synonyms.get(name) { - handler.emit_err(CompileError::ShadowsOtherSymbol { name: name.into() }); - } - }; - - match alias { - Some(alias) => { - check_name_clash(&alias); - dst_mod - .current_items_mut() - .use_item_synonyms - .insert(alias.clone(), (Some(item.clone()), src.to_vec(), decl)) - } - None => { - check_name_clash(item); - dst_mod - .current_items_mut() - .use_item_synonyms - .insert(item.clone(), (None, src.to_vec(), decl)) - } - }; + let mut impls_to_insert = TraitMap::default(); + if decl.is_typed() { + // We only handle trait imports when handling typed declarations, + // that is, when performing type-checking, and not when collecting. + // Update this once the type system is updated to refer to parsed + // declarations. + // if this is an enum or struct or function, import its implementations + if let Ok(type_id) = decl.return_type(&Handler::default(), engines) { + impls_to_insert.extend( + src_mod + .current_items() + .implemented_traits + .filter_by_type_item_import(type_id, engines), + engines, + ); + } + // if this is a trait, import its implementations + let decl_span = decl.span(engines); + if decl.is_trait() { + // TODO: we only import local impls from the source namespace + // this is okay for now but we'll need to device some mechanism to collect all available trait impls + impls_to_insert.extend( + src_mod + .current_items() + .implemented_traits + .filter_by_trait_decl_span(decl_span), + engines, + ); + } + } + + // no matter what, import it this way though. + let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; + let check_name_clash = |name| { + if dst_mod.current_items().use_item_synonyms.contains_key(name) { + handler.emit_err(CompileError::ShadowsOtherSymbol { name: name.into() }); + } + }; + match alias { + Some(alias) => { + check_name_clash(&alias); + dst_mod + .current_items_mut() + .use_item_synonyms + .insert(alias.clone(), (Some(item.clone()), path, decl, visibility)) } None => { - return Err(handler.emit_err(CompileError::SymbolNotFound { - name: item.clone(), - span: item.span(), - })); + check_name_clash(item); + dst_mod + .current_items_mut() + .use_item_synonyms + .insert(item.clone(), (None, path, decl, visibility)) } }; - let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; dst_mod .current_items_mut() .implemented_traits @@ -310,240 +415,85 @@ impl Root { variant_name: &Ident, dst: &ModulePath, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { self.check_module_privacy(handler, engines, src)?; let decl_engine = engines.de(); let parsed_decl_engine = engines.pe(); - let src_mod = self.module.lookup_submodule(handler, engines, src)?; - match src_mod.current_items().symbols.get(enum_name).cloned() { - Some(decl) => { - if !decl.visibility(engines).is_public() && !is_ancestor(src, dst) { - handler.emit_err(CompileError::ImportPrivateSymbol { - name: enum_name.clone(), - span: enum_name.span(), - }); - } + let (decl, path) = self.item_lookup(handler, engines, enum_name, src, dst)?; - match decl { - ResolvedDeclaration::Parsed(decl) => { - if let Declaration::EnumDeclaration(decl_id) = decl { - let enum_decl = parsed_decl_engine.get_enum(&decl_id); + match decl { + ResolvedDeclaration::Parsed(decl) => { + if let Declaration::EnumDeclaration(decl_id) = decl { + let enum_decl = parsed_decl_engine.get_enum(&decl_id); - if let Some(variant_decl) = - enum_decl.variants.iter().find(|v| v.name == *variant_name) - { - // import it this way. - let dst_mod = - self.module.lookup_submodule_mut(handler, engines, dst)?; - let check_name_clash = |name| { - if dst_mod.current_items().use_item_synonyms.contains_key(name) - { - handler.emit_err(CompileError::ShadowsOtherSymbol { - name: name.into(), - }); - } - }; - - match alias { - Some(alias) => { - check_name_clash(&alias); - dst_mod.current_items_mut().use_item_synonyms.insert( - alias.clone(), - ( - Some(variant_name.clone()), - src.to_vec(), - ResolvedDeclaration::Parsed( - Declaration::EnumVariantDeclaration( - EnumVariantDeclaration { - enum_ref: decl_id, - variant_name: variant_name.clone(), - variant_decl_span: variant_decl - .span - .clone(), - }, - ), - ), - ), - ); - } - None => { - check_name_clash(variant_name); - dst_mod.current_items_mut().use_item_synonyms.insert( - variant_name.clone(), - ( - None, - src.to_vec(), - ResolvedDeclaration::Parsed( - Declaration::EnumVariantDeclaration( - EnumVariantDeclaration { - enum_ref: decl_id, - variant_name: variant_name.clone(), - variant_decl_span: variant_decl - .span - .clone(), - }, - ), - ), - ), - ); - } - }; - } else { - return Err(handler.emit_err(CompileError::SymbolNotFound { - name: variant_name.clone(), - span: variant_name.span(), - })); + if let Some(variant_decl) = + enum_decl.variants.iter().find(|v| v.name == *variant_name) + { + // import it this way. + let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; + let check_name_clash = |name| { + if dst_mod.current_items().use_item_synonyms.contains_key(name) { + handler.emit_err(CompileError::ShadowsOtherSymbol { + name: name.into(), + }); } - } - } - ResolvedDeclaration::Typed(decl) => { - if let TyDecl::EnumDecl(ty::EnumDecl { decl_id, .. }) = decl { - let enum_decl = decl_engine.get_enum(&decl_id); - let enum_ref = DeclRef::new( - enum_decl.call_path.suffix.clone(), - decl_id, - enum_decl.span(), - ); - - if let Some(variant_decl) = - enum_decl.variants.iter().find(|v| v.name == *variant_name) - { - // import it this way. - let dst_mod = - self.module.lookup_submodule_mut(handler, engines, dst)?; - let check_name_clash = |name| { - if dst_mod.current_items().use_item_synonyms.contains_key(name) - { - handler.emit_err(CompileError::ShadowsOtherSymbol { - name: name.into(), - }); - } - }; - - match alias { - Some(alias) => { - check_name_clash(&alias); - dst_mod.current_items_mut().use_item_synonyms.insert( - alias.clone(), - ( - Some(variant_name.clone()), - src.to_vec(), - ResolvedDeclaration::Typed( - TyDecl::EnumVariantDecl(ty::EnumVariantDecl { - enum_ref: enum_ref.clone(), - variant_name: variant_name.clone(), - variant_decl_span: variant_decl - .span - .clone(), - }), - ), + }; + + match alias { + Some(alias) => { + check_name_clash(&alias); + dst_mod.current_items_mut().use_item_synonyms.insert( + alias.clone(), + ( + Some(variant_name.clone()), + path, + ResolvedDeclaration::Parsed( + Declaration::EnumVariantDeclaration( + EnumVariantDeclaration { + enum_ref: decl_id, + variant_name: variant_name.clone(), + variant_decl_span: variant_decl.span.clone(), + }, ), - ); - } - None => { - check_name_clash(variant_name); - dst_mod.current_items_mut().use_item_synonyms.insert( - variant_name.clone(), - ( - None, - src.to_vec(), - ResolvedDeclaration::Typed( - TyDecl::EnumVariantDecl(ty::EnumVariantDecl { - enum_ref: enum_ref.clone(), - variant_name: variant_name.clone(), - variant_decl_span: variant_decl - .span - .clone(), - }), - ), + ), + visibility, + ), + ); + } + None => { + check_name_clash(variant_name); + dst_mod.current_items_mut().use_item_synonyms.insert( + variant_name.clone(), + ( + None, + path, + ResolvedDeclaration::Parsed( + Declaration::EnumVariantDeclaration( + EnumVariantDeclaration { + enum_ref: decl_id, + variant_name: variant_name.clone(), + variant_decl_span: variant_decl.span.clone(), + }, ), - ); - } - }; - } else { - return Err(handler.emit_err(CompileError::SymbolNotFound { - name: variant_name.clone(), - span: variant_name.span(), - })); + ), + visibility, + ), + ); } - } else { - return Err(handler.emit_err(CompileError::Internal( - "Attempting to import variants of something that isn't an enum", - enum_name.span(), - ))); - } + }; + } else { + return Err(handler.emit_err(CompileError::SymbolNotFound { + name: variant_name.clone(), + span: variant_name.span(), + })); } } } - None => { - return Err(handler.emit_err(CompileError::SymbolNotFound { - name: enum_name.clone(), - span: enum_name.span(), - })); - } - }; - - Ok(()) - } - - /// Pull all variants from the enum `enum_name` from the given `src` module and import them all into the `dst` module. - /// - /// Paths are assumed to be absolute. - pub(crate) fn variant_star_import( - &mut self, - handler: &Handler, - engines: &Engines, - src: &ModulePath, - dst: &ModulePath, - enum_name: &Ident, - ) -> Result<(), ErrorEmitted> { - self.check_module_privacy(handler, engines, src)?; - - let parsed_decl_engine = engines.pe(); - let decl_engine = engines.de(); - - let src_mod = self.module.lookup_submodule(handler, engines, src)?; - let resolved_decl = src_mod.current_items().symbols.get(enum_name).cloned(); - - match resolved_decl { - Some(decl) => { - if !decl.visibility(engines).is_public() && !is_ancestor(src, dst) { - handler.emit_err(CompileError::ImportPrivateSymbol { - name: enum_name.clone(), - span: enum_name.span(), - }); - } - - if let ResolvedDeclaration::Parsed(Declaration::EnumDeclaration(decl_id)) = decl { - let enum_decl = parsed_decl_engine.get_enum(&decl_id); - - for variant in enum_decl.variants.iter() { - let variant_name = &variant.name; - let variant_decl = - Declaration::EnumVariantDeclaration(EnumVariantDeclaration { - enum_ref: decl_id, - variant_name: variant_name.clone(), - variant_decl_span: variant.span.clone(), - }); - - // import it this way. - self.module - .lookup_submodule_mut(handler, engines, dst)? - .current_items_mut() - .insert_glob_use_symbol( - engines, - variant_name.clone(), - src.to_vec(), - &ResolvedDeclaration::Parsed(variant_decl), - ); - } - } else if let ResolvedDeclaration::Typed(TyDecl::EnumDecl(ty::EnumDecl { - decl_id, - .. - })) = decl - { + ResolvedDeclaration::Typed(decl) => { + if let TyDecl::EnumDecl(ty::EnumDecl { decl_id, .. }) = decl { let enum_decl = decl_engine.get_enum(&decl_id); let enum_ref = DeclRef::new( enum_decl.call_path.suffix.clone(), @@ -551,26 +501,62 @@ impl Root { enum_decl.span(), ); - for variant_decl in enum_decl.variants.iter() { - let variant_name = &variant_decl.name; - let decl = ResolvedDeclaration::Typed(TyDecl::EnumVariantDecl( - ty::EnumVariantDecl { - enum_ref: enum_ref.clone(), - variant_name: variant_name.clone(), - variant_decl_span: variant_decl.span.clone(), - }, - )); - + if let Some(variant_decl) = + enum_decl.variants.iter().find(|v| v.name == *variant_name) + { // import it this way. - self.module - .lookup_submodule_mut(handler, engines, dst)? - .current_items_mut() - .insert_glob_use_symbol( - engines, - variant_name.clone(), - src.to_vec(), - &decl, - ); + let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; + let check_name_clash = |name| { + if dst_mod.current_items().use_item_synonyms.contains_key(name) { + handler.emit_err(CompileError::ShadowsOtherSymbol { + name: name.into(), + }); + } + }; + + match alias { + Some(alias) => { + check_name_clash(&alias); + dst_mod.current_items_mut().use_item_synonyms.insert( + alias.clone(), + ( + Some(variant_name.clone()), + path, + ResolvedDeclaration::Typed(TyDecl::EnumVariantDecl( + ty::EnumVariantDecl { + enum_ref: enum_ref.clone(), + variant_name: variant_name.clone(), + variant_decl_span: variant_decl.span.clone(), + }, + )), + visibility, + ), + ); + } + None => { + check_name_clash(variant_name); + dst_mod.current_items_mut().use_item_synonyms.insert( + variant_name.clone(), + ( + None, + path, + ResolvedDeclaration::Typed(TyDecl::EnumVariantDecl( + ty::EnumVariantDecl { + enum_ref: enum_ref.clone(), + variant_name: variant_name.clone(), + variant_decl_span: variant_decl.span.clone(), + }, + )), + visibility, + ), + ); + } + }; + } else { + return Err(handler.emit_err(CompileError::SymbolNotFound { + name: variant_name.clone(), + span: variant_name.span(), + })); } } else { return Err(handler.emit_err(CompileError::Internal( @@ -579,104 +565,94 @@ impl Root { ))); } } - None => { - return Err(handler.emit_err(CompileError::SymbolNotFound { - name: enum_name.clone(), - span: enum_name.span(), - })); - } }; Ok(()) } - /// Given a path to a `src` module, create synonyms to every symbol in that module to the given - /// `dst` module. - /// - /// This is used when an import path contains an asterisk. + /// Pull all variants from the enum `enum_name` from the given `src` module and import them all into the `dst` module. /// /// Paths are assumed to be absolute. - pub fn star_import_with_reexports( + pub(crate) fn variant_star_import( &mut self, handler: &Handler, engines: &Engines, src: &ModulePath, dst: &ModulePath, + enum_name: &Ident, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { self.check_module_privacy(handler, engines, src)?; - let src_mod = self.module.lookup_submodule(handler, engines, src)?; + let parsed_decl_engine = engines.pe(); + let decl_engine = engines.de(); - let implemented_traits = src_mod.current_items().implemented_traits.clone(); - let use_item_synonyms = src_mod.current_items().use_item_synonyms.clone(); - let use_glob_synonyms = src_mod.current_items().use_glob_synonyms.clone(); + let (decl, path) = self.item_lookup(handler, engines, enum_name, src, dst)?; - // collect all declared and reexported symbols from the source module - let mut all_symbols_and_decls: Vec<(Ident, ResolvedDeclaration)> = vec![]; - for (symbol, decls) in src_mod.current_items().use_glob_synonyms.iter() { - decls - .iter() - .for_each(|(_, decl)| all_symbols_and_decls.push((symbol.clone(), decl.clone()))); - } - for (symbol, (_, _, decl)) in src_mod.current_items().use_item_synonyms.iter() { - all_symbols_and_decls.push((symbol.clone(), decl.clone())); - } - for (symbol, decl) in src_mod.current_items().symbols.iter() { - if is_ancestor(src, dst) || decl.visibility(engines).is_public() { - all_symbols_and_decls.push((symbol.clone(), decl.clone())); + match decl { + ResolvedDeclaration::Parsed(Declaration::EnumDeclaration(decl_id)) => { + let enum_decl = parsed_decl_engine.get_enum(&decl_id); + + for variant in enum_decl.variants.iter() { + let variant_name = &variant.name; + let variant_decl = + Declaration::EnumVariantDeclaration(EnumVariantDeclaration { + enum_ref: decl_id, + variant_name: variant_name.clone(), + variant_decl_span: variant.span.clone(), + }); + + // import it this way. + self.module + .lookup_submodule_mut(handler, engines, dst)? + .current_items_mut() + .insert_glob_use_symbol( + engines, + variant_name.clone(), + path.clone(), + &ResolvedDeclaration::Parsed(variant_decl), + visibility, + ); + } } - } - - let mut symbols_paths_and_decls = vec![]; - let get_path = |mod_path: Vec| { - let mut is_external = false; - if let Some(submodule) = src_mod.submodule(engines, &[mod_path[0].clone()]) { - is_external = submodule.is_external - }; - - let mut path = src[..1].to_vec(); - if is_external { - path = mod_path; - } else { - path.extend(mod_path); + ResolvedDeclaration::Typed(TyDecl::EnumDecl(ty::EnumDecl { decl_id, .. })) => { + let enum_decl = decl_engine.get_enum(&decl_id); + let enum_ref = DeclRef::new( + enum_decl.call_path.suffix.clone(), + decl_id, + enum_decl.span(), + ); + + for variant_decl in enum_decl.variants.iter() { + let variant_name = &variant_decl.name; + let decl = + ResolvedDeclaration::Typed(TyDecl::EnumVariantDecl(ty::EnumVariantDecl { + enum_ref: enum_ref.clone(), + variant_name: variant_name.clone(), + variant_decl_span: variant_decl.span.clone(), + })); + + // import it this way. + self.module + .lookup_submodule_mut(handler, engines, dst)? + .current_items_mut() + .insert_glob_use_symbol( + engines, + variant_name.clone(), + path.clone(), + &decl, + visibility, + ); + } + } + _ => { + return Err(handler.emit_err(CompileError::Internal( + "Attempting to import variants of something that isn't an enum", + enum_name.span(), + ))); } - - path - }; - - for (symbol, (_, mod_path, decl)) in use_item_synonyms { - symbols_paths_and_decls.push((symbol, get_path(mod_path), decl)); - } - for (symbol, decls) in use_glob_synonyms { - decls.iter().for_each(|(mod_path, decl)| { - symbols_paths_and_decls.push(( - symbol.clone(), - get_path(mod_path.clone()), - decl.clone(), - )) - }); - } - - let dst_mod = self.module.lookup_submodule_mut(handler, engines, dst)?; - dst_mod - .current_items_mut() - .implemented_traits - .extend(implemented_traits, engines); - - let mut try_add = |symbol, path, decl: ResolvedDeclaration| { - dst_mod - .current_items_mut() - .insert_glob_use_symbol(engines, symbol, path, &decl); }; - for (symbol, decl) in all_symbols_and_decls { - try_add(symbol.clone(), src.to_vec(), decl); - } - - for (symbol, path, decl) in symbols_paths_and_decls { - try_add(symbol.clone(), path, decl); - } - Ok(()) } @@ -1015,7 +991,7 @@ impl Root { return Ok(decl.clone()); } // Check item imports - if let Some((_, _, decl)) = module.current_items().use_item_synonyms.get(symbol) { + if let Some((_, _, decl, _)) = module.current_items().use_item_synonyms.get(symbol) { return Ok(decl.clone()); } // Check glob imports @@ -1028,12 +1004,11 @@ impl Root { symbol.span(), ))); } else { - // Symbol not found return Err(handler.emit_err(CompileError::SymbolWithMultipleBindings { name: symbol.clone(), paths: decls .iter() - .map(|(path, decl)| { + .map(|(path, decl, _)| { let mut path_strs = path.iter().map(|x| x.to_string()).collect::>(); // Add the enum name to the path if the decl is an enum variant. diff --git a/sway-core/src/semantic_analysis/type_check_context.rs b/sway-core/src/semantic_analysis/type_check_context.rs index 959499bf3f3..daddfdaa947 100644 --- a/sway-core/src/semantic_analysis/type_check_context.rs +++ b/sway-core/src/semantic_analysis/type_check_context.rs @@ -1337,12 +1337,13 @@ impl<'a> TypeCheckContext<'a> { &mut self, handler: &Handler, src: &ModulePath, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let engines = self.engines; let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .star_import(handler, engines, src, &mod_path) + .star_import(handler, engines, src, &mod_path, visibility) } /// Short-hand for performing a [Module::variant_star_import] with `mod_path` as the destination. @@ -1351,12 +1352,13 @@ impl<'a> TypeCheckContext<'a> { handler: &Handler, src: &ModulePath, enum_name: &Ident, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let engines = self.engines; let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .variant_star_import(handler, engines, src, &mod_path, enum_name) + .variant_star_import(handler, engines, src, &mod_path, enum_name, visibility) } /// Short-hand for performing a [Module::self_import] with `mod_path` as the destination. @@ -1365,12 +1367,13 @@ impl<'a> TypeCheckContext<'a> { handler: &Handler, src: &ModulePath, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let engines = self.engines; let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .self_import(handler, engines, src, &mod_path, alias) + .self_import(handler, engines, src, &mod_path, alias, visibility) } // Import all impls for a struct/enum. Do nothing for other types. @@ -1419,12 +1422,13 @@ impl<'a> TypeCheckContext<'a> { src: &ModulePath, item: &Ident, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let engines = self.engines; let mod_path = self.namespace().mod_path.clone(); self.namespace_mut() .root - .item_import(handler, engines, src, item, &mod_path, alias) + .item_import(handler, engines, src, item, &mod_path, alias, visibility) } /// Short-hand for performing a [Module::variant_import] with `mod_path` as the destination. @@ -1436,6 +1440,7 @@ impl<'a> TypeCheckContext<'a> { enum_name: &Ident, variant_name: &Ident, alias: Option, + visibility: Visibility, ) -> Result<(), ErrorEmitted> { let engines = self.engines; let mod_path = self.namespace().mod_path.clone(); @@ -1447,6 +1452,7 @@ impl<'a> TypeCheckContext<'a> { variant_name, &mod_path, alias, + visibility, ) } diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 28337cc6c87..614b451e645 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -266,13 +266,6 @@ fn item_use_to_use_statements( handler: &Handler, item_use: ItemUse, ) -> Result, ErrorEmitted> { - if let Some(pub_token) = item_use.visibility { - let error = ConvertParseTreeError::PubUseNotSupported { - span: pub_token.span(), - }; - return Err(handler.emit_err(error.into())); - } - let mut ret = Vec::new(); let mut prefix = Vec::new(); let item_span = item_use.span(); @@ -280,6 +273,7 @@ fn item_use_to_use_statements( use_tree_to_use_statements( item_use.tree, item_use.root_import.is_some(), + pub_token_opt_to_visibility(item_use.visibility), &mut prefix, &mut ret, item_span, @@ -303,6 +297,7 @@ fn item_use_to_use_statements( fn use_tree_to_use_statements( use_tree: UseTree, is_absolute: bool, + reexport: Visibility, path: &mut Vec, ret: &mut Vec, item_span: Span, @@ -310,7 +305,14 @@ fn use_tree_to_use_statements( match use_tree { UseTree::Group { imports } => { for use_tree in imports.into_inner() { - use_tree_to_use_statements(use_tree, is_absolute, path, ret, item_span.clone()); + use_tree_to_use_statements( + use_tree, + is_absolute, + reexport, + path, + ret, + item_span.clone(), + ); } } UseTree::Name { name } => { @@ -324,6 +326,7 @@ fn use_tree_to_use_statements( span: item_span, import_type, is_absolute, + reexport, alias: None, }); } @@ -338,6 +341,7 @@ fn use_tree_to_use_statements( span: item_span, import_type, is_absolute, + reexport, alias: Some(alias), }); } @@ -347,12 +351,13 @@ fn use_tree_to_use_statements( span: item_span, import_type: ImportType::Star, is_absolute, + reexport, alias: None, }); } UseTree::Path { prefix, suffix, .. } => { path.push(prefix); - use_tree_to_use_statements(*suffix, is_absolute, path, ret, item_span); + use_tree_to_use_statements(*suffix, is_absolute, reexport, path, ret, item_span); path.pop().unwrap(); } UseTree::Error { .. } => { diff --git a/sway-error/src/convert_parse_tree_error.rs b/sway-error/src/convert_parse_tree_error.rs index 559a42bf772..2fdfdc58d75 100644 --- a/sway-error/src/convert_parse_tree_error.rs +++ b/sway-error/src/convert_parse_tree_error.rs @@ -3,8 +3,6 @@ use thiserror::Error; #[derive(Error, Debug, Clone, PartialEq, Eq, Hash)] pub enum ConvertParseTreeError { - #[error("pub use imports are not supported")] - PubUseNotSupported { span: Span }, #[error("Imports without items are not supported")] ImportsWithoutItemsNotSupported { span: Span }, #[error("functions used in applications may not be arbitrary expressions")] @@ -126,7 +124,6 @@ pub enum ConvertParseTreeError { impl Spanned for ConvertParseTreeError { fn span(&self) -> Span { match self { - ConvertParseTreeError::PubUseNotSupported { span } => span.clone(), ConvertParseTreeError::ImportsWithoutItemsNotSupported { span } => span.clone(), ConvertParseTreeError::FunctionArbitraryExpression { span } => span.clone(), ConvertParseTreeError::GenericsNotSupportedHere { span } => span.clone(), diff --git a/sway-lib-core/src/prelude.sw b/sway-lib-core/src/prelude.sw index 83fbeaa8627..cdec0239241 100644 --- a/sway-lib-core/src/prelude.sw +++ b/sway-lib-core/src/prelude.sw @@ -3,12 +3,12 @@ library; //! Defines the Sway core library prelude. //! The prelude consists of implicitly available items, //! for which `use` is not required. -use ::primitives::*; -use ::primitive_conversions::*; -use ::raw_ptr::*; -use ::raw_slice::*; -use ::never::*; -use ::ops::*; -use ::storage::*; -use ::str::*; -use ::codec::*; +pub use ::primitives::*; +pub use ::primitive_conversions::*; +pub use ::raw_ptr::*; +pub use ::raw_slice::*; +pub use ::never::*; +pub use ::ops::*; +pub use ::storage::*; +pub use ::str::*; +pub use ::codec::*; diff --git a/sway-lib-std/src/lib.sw b/sway-lib-std/src/lib.sw index bd1c213b1a2..fc09e123cd6 100644 --- a/sway-lib-std/src/lib.sw +++ b/sway-lib-std/src/lib.sw @@ -45,5 +45,3 @@ pub mod low_level_call; pub mod array_conversions; pub mod bytes_conversions; pub mod clone; - -use core::*; diff --git a/sway-lib-std/src/prelude.sw b/sway-lib-std/src/prelude.sw index 73fc1ae6e5d..6f207cc7b45 100644 --- a/sway-lib-std/src/prelude.sw +++ b/sway-lib-std/src/prelude.sw @@ -4,36 +4,36 @@ library; // Blockchain types -use ::address::Address; -use ::alias::SubId; -use ::asset_id::AssetId; -use ::contract_id::ContractId; -use ::identity::Identity; +pub use ::address::Address; +pub use ::alias::SubId; +pub use ::asset_id::AssetId; +pub use ::contract_id::ContractId; +pub use ::identity::Identity; // `StorageKey` API -use ::storage::storage_key::*; +pub use ::storage::storage_key::*; // Collections -use ::storage::storage_map::*; -use ::vec::{Vec, VecIter}; +pub use ::storage::storage_map::*; +pub use ::vec::{Vec, VecIter}; // Error handling -use ::assert::{assert, assert_eq, assert_ne}; -use ::option::Option::{self, *}; -use ::result::Result::{self, *}; -use ::revert::{require, revert}; +pub use ::assert::{assert, assert_eq, assert_ne}; +pub use ::option::Option::{self, *}; +pub use ::result::Result::{self, *}; +pub use ::revert::{require, revert}; // Convert -use ::convert::From; +pub use ::convert::From; // Primitive conversions -use ::primitive_conversions::{b256::*, str::*, u16::*, u256::*, u32::*, u64::*, u8::*,}; +pub use ::primitive_conversions::{b256::*, str::*, u16::*, u256::*, u32::*, u64::*, u8::*,}; // Logging -use ::logging::log; +pub use ::logging::log; // Auth -use ::auth::msg_sender; +pub use ::auth::msg_sender; // Math -use ::math::*; +pub use ::math::*; diff --git a/sway-lsp/tests/fixtures/tokens/abi/Forc.toml b/sway-lsp/tests/fixtures/tokens/abi/Forc.toml index 4063ea08089..cae34403d91 100644 --- a/sway-lsp/tests/fixtures/tokens/abi/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/abi/Forc.toml @@ -6,4 +6,7 @@ name = "abi" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/consts/Forc.toml b/sway-lsp/tests/fixtures/tokens/consts/Forc.toml index ce62f1fc216..59b51b9f27e 100644 --- a/sway-lsp/tests/fixtures/tokens/consts/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/consts/Forc.toml @@ -6,4 +6,7 @@ name = "consts" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/fields/Forc.toml b/sway-lsp/tests/fixtures/tokens/fields/Forc.toml index 961972e7bf2..ff0a1f99ea2 100644 --- a/sway-lsp/tests/fixtures/tokens/fields/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/fields/Forc.toml @@ -6,4 +6,7 @@ name = "fields" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/matches/Forc.toml b/sway-lsp/tests/fixtures/tokens/matches/Forc.toml index 9c40268a9be..8ff36fd28a7 100644 --- a/sway-lsp/tests/fixtures/tokens/matches/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/matches/Forc.toml @@ -6,4 +6,7 @@ name = "matches" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/paths/Forc.toml b/sway-lsp/tests/fixtures/tokens/paths/Forc.toml index 808b879d614..fa9bbd094d4 100644 --- a/sway-lsp/tests/fixtures/tokens/paths/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/paths/Forc.toml @@ -6,4 +6,7 @@ name = "paths" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/structs/Forc.toml b/sway-lsp/tests/fixtures/tokens/structs/Forc.toml index 80e834b458f..07828433fe5 100644 --- a/sway-lsp/tests/fixtures/tokens/structs/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/structs/Forc.toml @@ -6,4 +6,7 @@ name = "structs" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/turbofish/Forc.toml b/sway-lsp/tests/fixtures/tokens/turbofish/Forc.toml index 60ec45aa96e..ea4090c14c5 100644 --- a/sway-lsp/tests/fixtures/tokens/turbofish/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/turbofish/Forc.toml @@ -6,4 +6,7 @@ name = "turbofish" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/fixtures/tokens/variables/Forc.toml b/sway-lsp/tests/fixtures/tokens/variables/Forc.toml index 4aff801020f..8c9d4173a5e 100644 --- a/sway-lsp/tests/fixtures/tokens/variables/Forc.toml +++ b/sway-lsp/tests/fixtures/tokens/variables/Forc.toml @@ -6,4 +6,7 @@ name = "variables" implicit-std = false [dependencies] -std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +# TODO: This project needs the version of the preludes that uses `pub use` instead of `use` +# Temporarily use the local std before the tests dependencies are bumped to v0.61.3 or v0.62.0. +# std = { git = "https://github.com/FuelLabs/sway", tag = "v0.48.1" } +std = { path = "../../../../../sway-lib-std" } diff --git a/sway-lsp/tests/lib.rs b/sway-lsp/tests/lib.rs index d4187a182f5..6d726675236 100644 --- a/sway-lsp/tests/lib.rs +++ b/sway-lsp/tests/lib.rs @@ -414,7 +414,7 @@ fn go_to_definition_for_fields() { req_uri: &uri, req_line: 5, req_char: 8, - def_line: 81, + def_line: 82, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/option.sw", @@ -471,7 +471,7 @@ fn go_to_definition_inside_turbofish() { req_uri: &uri, req_line: 15, req_char: 12, - def_line: 81, + def_line: 82, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/option.sw", @@ -491,7 +491,7 @@ fn go_to_definition_inside_turbofish() { req_uri: &uri, req_line: 20, req_char: 19, - def_line: 61, + def_line: 62, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/result.sw", @@ -551,7 +551,7 @@ fn go_to_definition_for_matches() { req_uri: &uri, req_line: 25, req_char: 19, - def_line: 81, + def_line: 82, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/option.sw", @@ -569,7 +569,7 @@ fn go_to_definition_for_matches() { req_uri: &uri, req_line: 25, req_char: 27, - def_line: 85, + def_line: 86, def_start_char: 4, def_end_char: 8, def_path: "sway-lib-std/src/option.sw", @@ -584,7 +584,7 @@ fn go_to_definition_for_matches() { req_uri: &uri, req_line: 26, req_char: 17, - def_line: 83, + def_line: 84, def_start_char: 4, def_end_char: 8, def_path: "sway-lib-std/src/option.sw", @@ -706,7 +706,7 @@ fn go_to_definition_for_paths() { req_uri: &uri, req_line: 10, req_char: 27, - def_line: 81, + def_line: 82, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/option.sw", @@ -755,7 +755,7 @@ fn go_to_definition_for_paths() { req_uri: &uri, req_line: 12, req_char: 42, - def_line: 7, + def_line: 8, def_start_char: 11, def_end_char: 21, def_path: "sway-lib-std/src/vm/evm/evm_address.sw", @@ -906,30 +906,33 @@ fn go_to_definition_for_paths() { // assert lsp::definition_check(&server, &go_to).await; - let go_to = GotoDefinition { - req_uri: &uri, - req_line: 19, - req_char: 13, - def_line: 0, - def_start_char: 0, - def_end_char: 0, - def_path: "sway-lib-core/src/lib.sw", - }; - // core - lsp::definition_check(&server, &go_to).await; - - let mut go_to = GotoDefinition { - req_uri: &uri, - req_line: 19, - req_char: 21, - def_line: 0, - def_start_char: 0, - def_end_char: 0, - def_path: "sway-lib-core/src/primitives.sw", - }; - // primitives - lsp::definition_check(&server, &go_to).await; - lsp::definition_check_with_req_offset(&server, &mut go_to, 25, 20).await; + // TODO: This test stopped working when https://github.com/FuelLabs/sway/pull/6116 was merged. + // file:///home/cnn/Projects/sway/sway-lsp/tests/fixtures/tokens/paths/src/deep_mod.sw doesn't end with sway-lib-core/src/lib.sw + // let _go_to = GotoDefinition { + // req_uri: &uri, + // req_line: 33, + // req_char: 13, + // def_line: 0, + // def_start_char: 0, + // def_end_char: 0, + // def_path: "sway-lib-core/src/lib.sw", + // }; + // // core + // lsp::definition_check(&server, &go_to).await; + + // TODO: This test stopped working when https://github.com/FuelLabs/sway/pull/6116 was merged. + // let mut _go_to = GotoDefinition { + // req_uri: &uri, + // req_line: 33, + // req_char: 21, + // def_line: 0, + // def_start_char: 0, + // def_end_char: 0, + // def_path: "sway-lib-core/src/primitives.sw", + // }; + // // primitives + // lsp::definition_check(&server, &go_to).await; + // lsp::definition_check_with_req_offset(&server, &mut go_to, 25, 20).await; let go_to = GotoDefinition { req_uri: &uri, @@ -983,43 +986,46 @@ fn go_to_definition_for_paths() { lsp::definition_check_with_req_offset(&server, &mut go_to, 7, 11).await; lsp::definition_check_with_req_offset(&server, &mut go_to, 7, 23).await; - let mut go_to = GotoDefinition { - req_uri: &uri, - req_line: 24, - req_char: 31, - def_line: 33, - def_start_char: 10, - def_end_char: 19, - def_path: "sway-lib-std/src/constants.sw", - }; - // ZERO_B256 - lsp::definition_check(&server, &go_to).await; - lsp::definition_check_with_req_offset(&server, &mut go_to, 7, 31).await; - - let go_to = GotoDefinition { - req_uri: &uri, - req_line: 19, - req_char: 37, - def_line: 74, - def_start_char: 11, - def_end_char: 14, - def_path: "sway-lib-core/src/primitives.sw", - }; - // u64::min() - lsp::definition_check(&server, &go_to).await; - - let mut go_to = GotoDefinition { - req_uri: &uri, - req_line: 13, - req_char: 22, - def_line: 304, - def_start_char: 11, - def_end_char: 14, - def_path: "sway-lib-core/src/primitives.sw", - }; - // b256::min() - lsp::definition_check(&server, &go_to).await; - lsp::definition_check_with_req_offset(&server, &mut go_to, 25, 38).await; + // TODO: This test stopped working when https://github.com/FuelLabs/sway/pull/6116 was merged. + // let mut go_to = GotoDefinition { + // req_uri: &uri, + // req_line: 24, + // req_char: 31, + // def_line: 33, + // def_start_char: 10, + // def_end_char: 19, + // def_path: "sway-lib-std/src/constants.sw", + // }; + // // ZERO_B256 + // lsp::definition_check(&server, &go_to).await; + // lsp::definition_check_with_req_offset(&server, &mut go_to, 7, 31).await; + + // TODO: This test stopped working when https://github.com/FuelLabs/sway/pull/6116 was merged. + // let go_to = GotoDefinition { + // req_uri: &uri, + // req_line: 33, + // req_char: 37, + // def_line: 9, + // def_start_char: 11, + // def_end_char: 14, + // def_path: "sway-lib-core/src/primitives.sw", + // }; + // // u64::min() + // lsp::definition_check(&server, &go_to).await; + + // TODO: This test stopped working when https://github.com/FuelLabs/sway/pull/6116 was merged. + // let mut go_to = GotoDefinition { + // req_uri: &uri, + // req_line: 13, + // req_char: 22, + // def_line: 304, + // def_start_char: 11, + // def_end_char: 14, + // def_path: "sway-lib-core/src/primitives.sw", + // }; + // // b256::min() + // lsp::definition_check(&server, &go_to).await; + // lsp::definition_check_with_req_offset(&server, &mut go_to, 25, 38).await; // TODO: Uncomment when https://github.com/FuelLabs/sway/issues/4211 is fixed. // let go_to = GotoDefinition { @@ -1136,14 +1142,14 @@ fn go_to_definition_for_variables() { lsp::definition_check_with_req_offset(&server, &mut go_to, 53, 21).await; // Complex type ascriptions - go_to.def_line = 61; + go_to.def_line = 62; go_to.def_start_char = 9; go_to.def_end_char = 15; go_to.def_path = "sway-lib-std/src/result.sw"; lsp::definition_check_with_req_offset(&server, &mut go_to, 56, 22).await; lsp::definition_check_with_req_offset(&server, &mut go_to, 11, 31).await; lsp::definition_check_with_req_offset(&server, &mut go_to, 11, 60).await; - go_to.def_line = 81; + go_to.def_line = 82; go_to.def_path = "sway-lib-std/src/option.sw"; lsp::definition_check_with_req_offset(&server, &mut go_to, 56, 28).await; lsp::definition_check_with_req_offset(&server, &mut go_to, 11, 39).await; @@ -1177,7 +1183,7 @@ fn go_to_definition_for_consts() { req_uri: &uri, req_line: 9, req_char: 24, - def_line: 8, + def_line: 7, def_start_char: 11, def_end_char: 21, def_path: "sway-lib-std/src/contract_id.sw", @@ -1185,7 +1191,7 @@ fn go_to_definition_for_consts() { lsp::definition_check(&server, &contract_go_to).await; contract_go_to.req_char = 34; - contract_go_to.def_line = 40; + contract_go_to.def_line = 56; contract_go_to.def_start_char = 7; contract_go_to.def_end_char = 11; lsp::definition_check(&server, &contract_go_to).await; @@ -1229,7 +1235,7 @@ fn go_to_definition_for_consts() { lsp::definition_check_with_req_offset(&server, &mut go_to, 10, 17).await; // Complex type ascriptions - go_to.def_line = 81; + go_to.def_line = 82; go_to.def_start_char = 9; go_to.def_end_char = 15; go_to.def_path = "sway-lib-std/src/option.sw"; @@ -1324,7 +1330,7 @@ fn go_to_definition_for_structs() { req_uri: &uri, req_line: 16, req_char: 11, - def_line: 81, + def_line: 82, def_start_char: 9, def_end_char: 15, def_path: "sway-lib-std/src/option.sw", diff --git a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-assert/src/prelude.sw b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-assert/src/prelude.sw index 06236c60050..8384a72644d 100644 --- a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-assert/src/prelude.sw +++ b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-assert/src/prelude.sw @@ -4,8 +4,8 @@ library; // Error handling -use ::assert::{assert, assert_eq, assert_ne}; -use ::revert::{require, revert}; +pub use ::assert::{assert, assert_eq, assert_ne}; +pub use ::revert::{require, revert}; // Logging -use ::logging::log; +pub use ::logging::log; diff --git a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-conversions/src/prelude.sw b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-conversions/src/prelude.sw index 90fbbfa875c..7f98f5cd2b4 100644 --- a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-conversions/src/prelude.sw +++ b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-conversions/src/prelude.sw @@ -4,25 +4,25 @@ library; // Collections -use ::vec::{Vec, VecIter}; +pub use ::vec::{Vec, VecIter}; // Error handling -use ::assert::{assert, assert_eq, assert_ne}; -use ::option::Option::{self, *}; -use ::result::Result::{self, *}; -use ::revert::{require, revert}; +pub use ::assert::{assert, assert_eq, assert_ne}; +pub use ::option::Option::{self, *}; +pub use ::result::Result::{self, *}; +pub use ::revert::{require, revert}; // Convert -use ::convert::From; +pub use ::convert::From; /// U128 -use ::u128::*; +pub use ::u128::*; // Primitive conversions -use ::primitive_conversions::{b256::*, str::*, u16::*, u256::*, u32::*, u64::*, u8::*,}; +pub use ::primitive_conversions::{b256::*, str::*, u16::*, u256::*, u32::*, u64::*, u8::*,}; // Logging -use ::logging::log; +pub use ::logging::log; // Math -use ::math::*; +pub use ::math::*; diff --git a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-option-result/src/prelude.sw b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-option-result/src/prelude.sw index 1c6a59c2c6d..c96103fa4b0 100644 --- a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-option-result/src/prelude.sw +++ b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-option-result/src/prelude.sw @@ -4,10 +4,10 @@ library; // Error handling -use ::assert::{assert, assert_eq, assert_ne}; -use ::option::Option::{self, *}; -use ::result::Result::{self, *}; -use ::revert::{require, revert}; +pub use ::assert::{assert, assert_eq, assert_ne}; +pub use ::option::Option::{self, *}; +pub use ::result::Result::{self, *}; +pub use ::revert::{require, revert}; // Logging -use ::logging::log; +pub use ::logging::log; diff --git a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-vec/src/prelude.sw b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-vec/src/prelude.sw index 6d02ccb3dba..990bde12d23 100644 --- a/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-vec/src/prelude.sw +++ b/test/src/e2e_vm_tests/reduced_std_libs/sway-lib-std-vec/src/prelude.sw @@ -4,16 +4,16 @@ library; // Collections -use ::vec::{Vec, VecIter}; +pub use ::vec::{Vec, VecIter}; // Error handling -use ::assert::{assert, assert_eq, assert_ne}; -use ::option::Option::{self, *}; -use ::result::Result::{self, *}; -use ::revert::{require, revert}; +pub use ::assert::{assert, assert_eq, assert_ne}; +pub use ::option::Option::{self, *}; +pub use ::result::Result::{self, *}; +pub use ::revert::{require, revert}; // Convert -use ::convert::From; +pub use ::convert::From; // Logging -use ::logging::log; +pub use ::logging::log; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.lock new file mode 100755 index 00000000000..2f79b915015 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "aliases" +source = "member" +dependencies = ["std"] + +[[package]] +name = "core" +source = "path+from-root-D05BA88A39195D06" + +[[package]] +name = "std" +source = "path+from-root-D05BA88A39195D06" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.toml new file mode 100755 index 00000000000..5e3bdd0c704 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "aliases" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_2.sw new file mode 100755 index 00000000000..1fa9465b0ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub enum Items2_Variants { + Z: u64, + W: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_3.sw new file mode 100755 index 00000000000..c836a3b99dd --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_3.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: u64, +} + +pub enum Items3_Enum { + E: u64, + F: u64, +} + +pub enum Items3_Variants { + U: u64, + V: u64, +} + +pub const ITEMS_3_FUNCTION_RES = 3872; + +pub fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_4.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_4.sw new file mode 100755 index 00000000000..5c297e872ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_4.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + G: u64, + H: u64, +} + +pub enum Items4_Variants { + S: u64, + T: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 14278; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_5.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_5.sw new file mode 100755 index 00000000000..72f5360035e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/items_5.sw @@ -0,0 +1,5 @@ +library; + +pub trait Items5Trait { + fn items_5_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_1.sw new file mode 100644 index 00000000000..d40aca7a5f1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct as Alias1_Struct; + +pub use ::items_1::Items1_Enum as Alias1_Enum; + +pub use ::items_1::Items1_Variants::X as Alias1_X; +pub use ::items_1::Items1_Variants::Y as Alias1_Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES as ALIAS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function as alias_1_function; + +pub use ::items_1::Items1Trait as Alias1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_2.sw new file mode 100644 index 00000000000..26b2411e634 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_2::Items2_Struct as Alias2_Struct; + +pub use ::items_2::Items2_Enum as Alias2_Enum; + +pub use ::items_2::Items2_Variants::Z as Alias2_Z; +pub use ::items_2::Items2_Variants::W as Alias2_W; + +pub use ::items_2::ITEMS_2_FUNCTION_RES as ALIAS_2_FUNCTION_RES; + +pub use ::items_2::items_2_function as alias_2_function; + +pub use ::items_2::Items2Trait as Alias2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_3.sw new file mode 100644 index 00000000000..9476211085e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_3.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_3::Items3_Struct as Alias3_Struct; + +pub use ::items_3::Items3_Enum as Alias3_Enum; + +pub use ::items_3::Items3_Variants::U as Alias3_U; +pub use ::items_3::Items3_Variants::V as Alias3_V; + +pub use ::items_3::ITEMS_3_FUNCTION_RES as ALIAS_3_FUNCTION_RES; + +pub use ::items_3::items_3_function as alias_3_function; + +pub use ::items_3::Items3Trait as Alias3Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_1.sw new file mode 100644 index 00000000000..6817b4e8aa5 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_4::Items4_Struct as Alias4_Struct; + +pub use ::items_4::Items4_Enum as Alias4_Enum; + +pub use ::items_4::Items4_Variants::S as Alias4_S; +pub use ::items_4::Items4_Variants::T as Alias4_T; + +pub use ::items_4::ITEMS_4_FUNCTION_RES as ALIAS_4_FUNCTION_RES; + +pub use ::items_4::items_4_function as alias_4_function; + +pub use ::items_4::Items4Trait as Alias4Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_2.sw new file mode 100644 index 00000000000..229326aba37 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_4_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::lib_4_1::Alias4_Struct as AltAlias4_Struct; + +pub use ::lib_4_1::Alias4_Enum as AltAlias4_Enum; + +pub use ::lib_4_1::Alias4_S as AltAlias4_S; +pub use ::lib_4_1::Alias4_T as AltAlias4_T; + +pub use ::lib_4_1::ALIAS_4_FUNCTION_RES as ALTALIAS_4_FUNCTION_RES; + +pub use ::lib_4_1::alias_4_function as altalias_4_function; + +pub use ::lib_4_1::Alias4Trait as AltAlias4Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_1.sw new file mode 100644 index 00000000000..fdb5c12af94 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_1.sw @@ -0,0 +1,3 @@ +library; + +pub use ::items_5::Items5Trait as Alias5Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_2.sw new file mode 100644 index 00000000000..e2206b6136b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/lib_5_2.sw @@ -0,0 +1,3 @@ +library; + +pub use ::items_5::Items5Trait as AltAlias5Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/main.sw new file mode 100755 index 00000000000..d84157a1bce --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/main.sw @@ -0,0 +1,20 @@ +script; + +mod items_1; +mod lib_1; // Aliased item reexports of items_1 +mod items_2; +mod lib_2; // Aliased item reexports of items_2 +mod items_3; +mod lib_3; // Aliased item reexports of items_3 +mod items_4; +mod lib_4_1; // Aliased item reexports of items_4 +mod lib_4_2; // Aliased item reexports of lib_4_1 +mod items_5; +mod lib_5_1; // Aliased trait reexports from items_5 +mod lib_5_2; // Aliased trait reexports from items_5 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/tests.sw new file mode 100644 index 00000000000..a89efa89d2e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/src/tests.sw @@ -0,0 +1,184 @@ +library; + +// Reexported items from items_1.sw. All reexports aliased by lib_1 +use ::lib_1::Items1_Struct; +use ::lib_1::Items1_Enum; +use ::lib_1::Items1_X; +use ::lib_1::Items1_Y; +use ::lib_1::ITEMS_1_FUNCTION_RES; +use ::lib_1::items_1_function; +use ::lib_1::Items1Trait; + +use ::items_1::Items1_Variants; + +// Reexported items from items_2.sw. All reexports aliased by lib_2 +use ::lib_2::Alias2_Struct; +use ::lib_2::Alias2_Enum; +use ::lib_2::Alias2_Z; +use ::lib_2::Alias2_W; +use ::lib_2::ALIAS_2_FUNCTION_RES; +use ::lib_2::alias_2_function; +use ::lib_2::Alias2Trait; + +use ::items_2::Items2_Variants; + +// Reexported items from items_3.sw. All reexports aliased by lib_3 +use ::lib_3::*; + +use ::items_3::Items3_Variants; + +// Reexported items from items_4.sw. All reexports aliased by lib_4_1 and realiased by lib_4_2 +use ::lib_4_2::Alias4_Struct; +use ::lib_4_2::Alias4_Enum; +use ::lib_4_2::Alias4_S; +use ::lib_4_2::Alias4_T; +use ::lib_4_2::ALIAS_4_FUNCTION_RES; +use ::lib_4_2::alias_4_function; +use ::lib_4_2::Alias4Trait; + +// Reexported trait from items_5.sw. Aliased both by lib_5_1 and by lib_5_2 +use ::lib_5_1::*; +use ::lib_5_2::*; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.a +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::A(val) => val, + Items2_Enum::B(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + Items2_X(val) => val, + Items2_Y(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_3 tests + +fn project_items_3_struct(input: Items3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: Items3_Enum) -> u64 { + match input { + Items3_Enum::E(val) => val, + Items3_Enum::F(val) => val + 1000, + } +} + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + Items3_U(val) => val, + Items3_V(val) => val + 1000, + } +} + +fn call_items_3_function() -> u64 { + items_3_function() +} + +impl Items3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + +// lib_5 tests + +// Alias5Trait and AltAlias5Trait refer to the same trait, but no error is reported for multiple +// impls of same trait for same type. +impl Alias5Trait for TestStruct1 { + fn items_5_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + +impl AltAlias5Trait for TestStruct1 { + fn items_5_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + + + +pub fn run_all_tests() -> u64 { + let items_2_struct = Items2_Struct { b: 123 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 123); + + let items_2_enum = Items2_Enum::C(432); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 432); + + let items_2_variants = Z(680); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 680); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + + let items_3_struct = Items3_Struct { c: 123 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 123); + + let items_3_enum = Items3_Enum::E(432); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 432); + + let items_3_variants = U(680); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 680); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ITEMS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res); + + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_5_trait_teststruct_1_res = teststruct_1.items_5_trait_function(teststruct_2); + assert(items_5_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/test.toml new file mode 100755 index 00000000000..8d07f8ae8dc --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/aliases/test.toml @@ -0,0 +1,188 @@ +category = "fail" + +#check: $()error +#check: $()use ::lib_1::Items1_Struct; +#nextln: $()Could not find symbol "Items1_Struct" in this scope. + +#check: $()error +#check: $()use ::lib_1::Items1_Enum; +#nextln: $()Could not find symbol "Items1_Enum" in this scope. + +#check: $()error +#check: $()use ::lib_1::Items1_X; +#nextln: $()Could not find symbol "Items1_X" in this scope. + +#check: $()error +#check: $()use ::lib_1::Items1_Y; +#nextln: $()Could not find symbol "Items1_Y" in this scope. + +#check: $()error +#check: $()use ::lib_1::ITEMS_1_FUNCTION_RES; +#nextln: $()Could not find symbol "ITEMS_1_FUNCTION_RES" in this scope. + +#check: $()error +#check: $()use ::lib_1::items_1_function; +#nextln: $()Could not find symbol "items_1_function" in this scope. + +#check: $()error +#check: $()use ::lib_1::Items1Trait; +#nextln: $()Could not find symbol "Items1Trait" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::Alias4_Struct; +#nextln: $()Could not find symbol "Alias4_Struct" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::Alias4_Enum; +#nextln: $()Could not find symbol "Alias4_Enum" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::Alias4_S; +#nextln: $()Could not find symbol "Alias4_S" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::Alias4_T; +#nextln: $()Could not find symbol "Alias4_T" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::ALIAS_4_FUNCTION_RES; +#nextln: $()Could not find symbol "ALIAS_4_FUNCTION_RES" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::alias_4_function; +#nextln: $()Could not find symbol "alias_4_function" in this scope. + +#check: $()error +#check: $()use ::lib_4_2::Alias4Trait; +#nextln: $()Could not find symbol "Alias4Trait" in this scope. + +#check: $()error +#check: $()fn project_items_2_struct(input: Items2_Struct) -> u64 { +#nextln: $()Could not find symbol "Items2_Struct" in this scope. + +#check: $()error +#check: $()fn project_items_2_struct(input: Items2_Struct) -> u64 { +#nextln: $()Unknown type name "Items2_Struct". + +#check: $()error +#check: $()fn project_items_2_enum(input: Items2_Enum) -> u64 { +#nextln: $()Could not find symbol "Items2_Enum" in this scope. + +#check: $()error +#check: $()fn project_items_2_enum(input: Items2_Enum) -> u64 { +#nextln: $()Unknown type name "Items2_Enum". + +#check: $()error +#check: $()Items2_X(val) => val, +#nextln: $()Could not find symbol "Items2_X" in this scope. + +#check: $()error +#check: $()Items2_Y(val) => val + 1000, +#nextln: $()Could not find symbol "Items2_Y" in this scope. + +#check: $()error +#check: $()fn call_items_2_function() -> u64 { +#nextln: $()items_2_function() +#nextln: $()Could not find symbol "items_2_function" in this scope. + +#check: $()error +#check: $()impl Items2Trait for TestStruct1 { +#nextln: $()Could not find symbol "Items2Trait" in this scope. + +#check: $()error +#check: $()impl Items2Trait for TestStruct1 { +#nextln: $()Trait "Items2Trait" cannot be found in the current scope. + +#check: $()error +#check: $()let items_2_struct = Items2_Struct { b: 123 }; +#nextln: $()Could not find symbol "Items2_Struct" in this scope. + +#check: $()error +#check: $()let items_2_struct = Items2_Struct { b: 123 }; +#nextln: $()Unknown type name "Items2_Struct". + +#check: $()error +#check: $()let items_2_struct_res = project_items_2_struct(items_2_struct); +#nextln: $()Could not find symbol "project_items_2_struct" in this scope. + +#check: $()error +#check: $()assert(items_2_struct_res == 123); +#nextln: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()let items_2_enum = Items2_Enum::C(432); +#nextln: $()Could not find symbol "Items2_Enum" in this scope. + +#check: $()error +#check: $()let items_2_enum = Items2_Enum::C(432); +#nextln: $()Unknown type name "Items2_Enum". + +#check: $()error +#check: $()let items_2_enum_res = project_items_2_enum(items_2_enum); +#nextln: $()Could not find symbol "project_items_2_enum" in this scope. + +#check: $()error +#check: $()assert(items_2_enum_res == 432); +#nextln: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()let items_2_variants = Z(680); +#nextln: $()Could not find symbol "Z" in this scope. + +#check: $()error +#check: $()assert(items_2_function_res == ITEMS_2_FUNCTION_RES); +#nextln: $()Variable "ITEMS_2_FUNCTION_RES" does not exist in this scope. + +#check: $()error +#check: $()let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); +#nextln: $()No method named "items_2_trait_function" found for type "TestStruct1". + +#check: $()error +#check: $()let items_3_struct = Items3_Struct { c: 123 }; +#nextln: $()Could not find symbol "Items3_Struct" in this scope. + +#check: $()error +#check: $()let items_3_struct = Items3_Struct { c: 123 }; +#nextln: $()Unknown type name "Items3_Struct". + +#check: $()error +#check: $()let items_3_struct_res = project_items_3_struct(items_3_struct); +#nextln: $()Could not find symbol "project_items_3_struct" in this scope. + +#check: $()error +#check: $()assert(items_3_struct_res == 123); +#nextln: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()let items_3_enum = Items3_Enum::E(432); +#nextln: $()Could not find symbol "Items3_Enum" in this scope. + +#check: $()error +#check: $()let items_3_enum = Items3_Enum::E(432); +#nextln: $()Unknown type name "Items3_Enum". + +#check: $()error +#check: $()let items_3_enum_res = project_items_3_enum(items_3_enum); +#nextln: $()Could not find symbol "project_items_3_enum" in this scope. + +#check: $()error +#check: $()assert(items_3_enum_res == 432); +#nextln: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()let items_3_variants = U(680); +#nextln: $()Could not find symbol "U" in this scope. + +#check: $()error +#check: $()assert(items_3_function_res == ITEMS_3_FUNCTION_RES); +#nextln: $()Variable "ITEMS_3_FUNCTION_RES" does not exist in this scope. + +#check: $()error +#check: $()let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); +#nextln: $()No method named "items_3_trait_function" found for type "TestStruct1". + +#check: $()error +#check: $()let items_5_trait_teststruct_1_res = teststruct_1.items_5_trait_function(teststruct_2); +#nextln: $()Multiple applicable items in scope. + +#check: $()Aborting due to 55 errors. \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.lock new file mode 100755 index 00000000000..d59e66c3300 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-5E33A7D67412F1BB" + +[[package]] +name = "multiple_imports_of_same_reexport" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-5E33A7D67412F1BB" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.toml new file mode 100755 index 00000000000..06785d8428a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "multiple_imports_of_same_reexport" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw new file mode 100644 index 00000000000..9d3a4594442 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw @@ -0,0 +1,4 @@ +library; + +pub use ::items_1::*; +pub use ::items_1::Items1_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw new file mode 100644 index 00000000000..9d3a4594442 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw @@ -0,0 +1,4 @@ +library; + +pub use ::items_1::*; +pub use ::items_1::Items1_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/main.sw new file mode 100755 index 00000000000..c4f06aaf84f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/main.sw @@ -0,0 +1,11 @@ +script; + +mod items_1; +mod lib_1_1; // Item reexports of items_1 +mod lib_1_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/tests.sw new file mode 100644 index 00000000000..dc263b07cf5 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/src/tests.sw @@ -0,0 +1,88 @@ +library; + +// Both lib_1_1.sw and lib_1_2.sw reexport items from items_1.sw. All reexports are star imports. +// Importing individual items from both lib_1_1 and lib_1_2 causes a name clash. +// (The fact that they refer to the same item is irrelevant, since it is also an error to import the +// same item twice from the same source) +use ::lib_1_1::Items1_Struct; +use ::lib_1_1::Items1_Enum; +use ::lib_1_1::Items1_Variants::X; +use ::lib_1_1::Items1_Variants::Y; +use ::lib_1_1::ITEMS_1_FUNCTION_RES; +use ::lib_1_1::items_1_function; +use ::lib_1_1::Items1Trait; + +use ::lib_1_2::Items1_Struct; +use ::lib_1_2::Items1_Enum; +use ::lib_1_2::Items1_Variants::X; +use ::lib_1_2::Items1_Variants::Y; +use ::lib_1_2::ITEMS_1_FUNCTION_RES; +use ::lib_1_2::items_1_function; +use ::lib_1_2::Items1Trait; + +use ::items_1::Items1_Variants; + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + +// items_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/test.toml new file mode 100755 index 00000000000..304d05109d3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/multiple_imports_of_same_reexport/test.toml @@ -0,0 +1,31 @@ +category = "fail" + +#check: $()error +#check: $()use ::lib_1_2::Items1_Struct; +#nextln: $()The imported symbol "Items1_Struct" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::Items1_Enum; +#nextln: $()The imported symbol "Items1_Enum" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::Items1_Variants::X; +#nextln: $()The imported symbol "X" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::Items1_Variants::Y; +#nextln: $()The imported symbol "Y" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::ITEMS_1_FUNCTION_RES; +#nextln: $()The imported symbol "ITEMS_1_FUNCTION_RES" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::items_1_function; +#nextln: $()The imported symbol "items_1_function" shadows another symbol with the same name. + +#check: $()error +#check: $()use ::lib_1_2::Items1Trait; +#nextln: $()The imported symbol "Items1Trait" shadows another symbol with the same name. + +#check: $()Aborting due to 7 errors. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.lock new file mode 100755 index 00000000000..ac25cb26c8e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-EE202EE2D1735C08" + +[[package]] +name = "shadowing_in_reexporting_module" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-EE202EE2D1735C08" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.toml new file mode 100755 index 00000000000..4b87dd678a8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "shadowing_in_reexporting_module" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_1.sw new file mode 100644 index 00000000000..95b236919b7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_1.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items1_Struct { + pub a: bool, +} + +pub enum Items1_Enum { + A: bool, + B: bool, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> bool { + ITEMS_1_FUNCTION_RES == 456 +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw new file mode 100644 index 00000000000..f00aa5f00c7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items2_Struct { + pub b: bool, +} + +pub enum Items2_Enum { + C: bool, + D: bool, +} + +pub const ITEMS_2_FUNCTION_RES = 789; + +pub fn items_2_function() -> bool { + ITEMS_2_FUNCTION_RES == 789 +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw new file mode 100644 index 00000000000..6822e86d865 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw new file mode 100644 index 00000000000..86138d9e3ed --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: bool, +} + +pub enum Items3_Enum { + E: bool, + F: bool, +} + +pub enum Items3_Variants { + G: bool, + H: bool, +} + +pub const ITEMS_3_FUNCTION_RES = 1234; + +pub fn items_3_function() -> bool { + ITEMS_3_FUNCTION_RES == 1234 +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw new file mode 100644 index 00000000000..2d9be57fc13 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: bool, +} + +pub enum Items4_Enum { + I: bool, + J: bool, +} + +pub enum Items4_Variants { + K: bool, + L: bool, +} + +pub const ITEMS_4_FUNCTION_RES = 5678; + +pub fn items_4_function() -> bool { + ITEMS_4_FUNCTION_RES == 5678 +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw new file mode 100644 index 00000000000..d57d5b3fbc6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + I: u64, + J: u64, +} + +pub enum Items4_Variants { + K: u64, + L: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 8765; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw new file mode 100644 index 00000000000..92293307319 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw @@ -0,0 +1,6 @@ +library; + +pub enum Items4_Variants2 { + M: bool, + N: bool, +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw new file mode 100644 index 00000000000..2f9d86748af --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw @@ -0,0 +1,6 @@ +library; + +pub enum Items4_Variants2 { + M: u64, + N: u64, +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw new file mode 100644 index 00000000000..783403a1e47 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw @@ -0,0 +1,22 @@ +library; + +pub use ::items_1::*; + +struct Items1_Struct { + a: u64, +} + +enum Items1_Enum { + A: u64, + B: u64, +} + +const ITEMS_1_FUNCTION_RES = 654; + +fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +trait Items1Trait { + fn items_1_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw new file mode 100644 index 00000000000..a249d995c9d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw @@ -0,0 +1,9 @@ +library; + +pub use ::items_2_1::*; + +use ::items_2_2::Items2_Struct; +use ::items_2_2::Items2_Enum; +use ::items_2_2::ITEMS_2_FUNCTION_RES; +use ::items_2_2::items_2_function; +use ::items_2_2::Items2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw new file mode 100644 index 00000000000..6ed081d11ef --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw @@ -0,0 +1,28 @@ +library; + +pub use ::items_3_1::*; +pub use ::items_3_1::Items3_Variants::*; + +struct Items3_Struct { + pub c: u64, +} + +enum Items3_Enum { + E: u64, + F: u64, +} + +enum Items3_Variants { + G: u64, + H: u64, +} + +const ITEMS_3_FUNCTION_RES = 4321; + +fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +trait Items3Trait { + fn items_3_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw new file mode 100644 index 00000000000..df9383b3da2 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw @@ -0,0 +1,17 @@ +library; + +pub use ::items_4_1::*; +pub use ::items_4_1::Items4_Variants::*; + +use ::items_4_2::Items4_Struct; +use ::items_4_2::Items4_Enum; +use ::items_4_2::Items4_Variants; +use ::items_4_2::Items4_Variants::K; +use ::items_4_2::Items4_Variants::L; +use ::items_4_2::ITEMS_4_FUNCTION_RES; +use ::items_4_2::items_4_function; +use ::items_4_2::Items4Trait; + +pub use ::items_4_3::Items4_Variants2::*; +use ::items_4_4::Items4_Variants2::M; +use ::items_4_4::Items4_Variants2::N; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/main.sw new file mode 100755 index 00000000000..a2961173628 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/main.sw @@ -0,0 +1,20 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2_1; +mod items_2_2; +mod lib_2; // Item reexports of items_2_1 and items_2_2 +mod items_3_1; +mod lib_3; // Item reexports of items_3_1 and items_3_2 +mod items_4_1; +mod items_4_2; +mod items_4_3; +mod items_4_4; +mod lib_4; // Item reexports of items_4_1 and items_4_2 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/tests.sw new file mode 100644 index 00000000000..2457aeacce0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/src/tests.sw @@ -0,0 +1,273 @@ +library; + +// Reexported items from items_1.sw. All reexports shadowed by private local definitions in lib_1.sw. +use ::lib_1::*; + // Reexported items from items_2_1.sw and items_2_2.sw. All reexports from items_2_1.sw are + // shadowed by items imported and not reexported from items_2_2.sw +use ::lib_2::*; +// Reexported items from items_3_1.sw and items_3_2.sw. All reexports shadowed by private local +// definitions in lib_3.sw. +use ::lib_3::Items3_Struct; +use ::lib_3::Items3_Enum; +use ::lib_3::Items3_Variants; +use ::lib_3::Items3_Variants::G; +use ::lib_3::Items3_Variants::H; +use ::lib_3::ITEMS_3_FUNCTION_RES; +use ::lib_3::items_3_function; +use ::lib_3::Items3Trait; + +// Reexported items from items_4_1.sw and items_4_2.sw. All reexports from items_4_1.sw are +// shadowed by items imported and not reexported from items_4_2.sw +use ::lib_4::Items4_Struct; +use ::lib_4::Items4_Enum; +use ::lib_4::Items4_Variants; + +// This ought to be possible, but Items4_Variants is interpreted as a module rather than as an enum. +use ::lib_4::Items4_Variants::K; +use ::lib_4::Items4_Variants::L; +// Using the variant names directly works, but that's not how the test should work. +// Uncomment the previous two imports and remove these next two when the problem has been resolved. +//use ::lib_4::K; +//use ::lib_4::L; + +use ::lib_4::ITEMS_4_FUNCTION_RES; +use ::lib_4::items_4_function; +use ::lib_4::Items4Trait; +// Items4_Variants2 defined in items_4_4.sw, variants reexported by lib_4.sw +use ::items_4_4::Items4_Variants2; +use ::lib_4::M; +use ::lib_4::N; + + + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + self.Z + } + else { + 0 + } + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::C(val) => val, + Items2_Enum::D(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + 0 + } + else { + self.Z + } + } +} + + +// lib_3 tests + +fn project_items_3_struct(input: Items3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: Items3_Enum) -> u64 { + match input { + Items3_Enum::E(val) => val, + Items3_Enum::F(val) => val + 1000, + } +} + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + Items3_Variants::G(val) => val, + Items3_Variants::H(val) => val + 1000, + } +} + +fn call_items_3_function() -> u64 { + items_3_function() +} + +impl Items3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + self.Z + } + else { + 0 + } + } +} + +// lib_4 tests + +fn project_items_4_struct(input: Items4_Struct) -> u64 { + input.d +} + +fn project_items_4_enum(input: Items4_Enum) -> u64 { + match input { + Items4_Enum::I(val) => val, + Items4_Enum::J(val) => val + 1000, + } +} + +fn project_items_4_variants(input: Items4_Variants) -> u64 { + match input { + K(val) => val, + L(val) => val + 1000, + } +} + +fn call_items_4_function() -> u64 { + items_4_function() +} + +impl Items4Trait for TestStruct1 { + fn items_4_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + 0 + } + else { + self.Z + } + } +} + +fn project_items_4_variants2(input: Items4_Variants2) -> u64 { + match input { + M(val) => val, + N(val) => val + 1000, + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res == 64); + + + let items_2_struct = Items2_Struct { b: 879 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 879); + + let items_2_enum = Items2_Enum::C(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res == 128); + + + let items_3_struct = Items3_Struct { c: 123 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 123); + + let items_3_enum = Items3_Enum::E(432); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 432); + + let items_3_variants = G(432); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 432); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ITEMS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res == 64); + + + let items_4_struct = Items4_Struct { d: 879 }; + let items_4_struct_res = project_items_4_struct(items_4_struct); + assert(items_4_struct_res == 879); + + let items_4_enum = Items4_Enum::I(446); + let items_4_enum_res = project_items_4_enum(items_4_enum); + assert(items_4_enum_res == 446); + + let items_4_variants = K(446); + let items_4_variants_res = project_items_4_variants(items_4_variants); + assert(items_4_variants_res == 446); + + let items_4_function_res = call_items_4_function(); + assert(items_4_function_res == ITEMS_4_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 148 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_4_trait_teststruct_1_res = teststruct_1.items_4_trait_function(teststruct_2); + assert(items_4_trait_teststruct_1_res == 148); + + let items_4_variants2 = M(446); + let items_4_variants2_res = project_items_4_variants2(items_4_variants2); + assert(items_4_variants2_res == 446); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/test.toml new file mode 100755 index 00000000000..9ba4d7f4a66 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/shadowing_in_reexporting_module/test.toml @@ -0,0 +1,191 @@ +category = "fail" + +#check: $()error +#check: $()use ::lib_3::Items3_Struct; +#nextln: $()Symbol "Items3_Struct" is private. + +#check: $()error +#check: $()use ::lib_3::Items3_Enum; +#nextln: $()Symbol "Items3_Enum" is private. + +#check: $()error +#check: $()use ::lib_3::Items3_Variants; +#nextln: $()Symbol "Items3_Variants" is private. + +#check: $()error +#check: $()use ::lib_3::Items3_Variants::G; +#nextln: $()Symbol "Items3_Variants" is private. + +#check: $()error +#check: $()use ::lib_3::Items3_Variants::H; +#nextln: $()Symbol "Items3_Variants" is private. + +#check: $()error +#check: $()use ::lib_3::ITEMS_3_FUNCTION_RES; +#nextln: $()Symbol "ITEMS_3_FUNCTION_RES" is private. + +#check: $()error +#check: $()use ::lib_3::items_3_function; +#nextln: $()Symbol "items_3_function" is private. + +#check: $()error +#check: $()use ::lib_3::Items3Trait; +#nextln: $()Symbol "Items3Trait" is private. + +#check: $()error +#check: $()use ::lib_4::Items4_Struct; +#nextln: $()Symbol "Items4_Struct" is private. + +#check: $()error +#check: $()use ::lib_4::Items4_Enum; +#nextln: $()Symbol "Items4_Enum" is private. + +#check: $()error +#check: $()use ::lib_4::Items4_Variants; +#nextln: $()Symbol "Items4_Variants" is private. + +#check: $()error +#check: $()use ::lib_4::Items4_Variants::K; +#nextln: $()Symbol "Items4_Variants" is private. + +#check: $()error +#check: $()use ::lib_4::Items4_Variants::L; +#nextln: $()Symbol "Items4_Variants" is private. + +#check: $()error +#check: $()use ::lib_4::ITEMS_4_FUNCTION_RES; +#nextln: $()Symbol "ITEMS_4_FUNCTION_RES" is private. + +#check: $()error +#check: $()use ::lib_4::items_4_function; +#nextln: $()Symbol "items_4_function" is private. + +#check: $()error +#check: $()use ::lib_4::Items4Trait; +#nextln: $()Symbol "Items4Trait" is private. + +#check: $()error +#check: $()use ::lib_4::M; +#nextln: $()Symbol "M" is private. + +#check: $()error +#check: $()use ::lib_4::N; +#nextln: $()Symbol "N" is private. + +#check: $()error +#check: $()input.a +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()input.a +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()Items1_Enum::A(val) => val, +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()Items1_Enum::B(val) => val + 1000, +#nextln: $()No method named "add" found for type "bool". + +#check: $()error +#check: $()items_1_function() +#check: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()items_1_function() +#check: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()fn items_1_trait_function(self, x: TestStruct2) -> u64 { +#nextln: $()expected: bool +#nextln: $()found: u64 + +#check: $()error +#check: $()input.b +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()input.b +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()Items2_Enum::C(val) => val, +#nextln: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()Items2_Enum::D(val) => val + 1000, +#nextln: $()No method named "add" found for type "bool". + +#check: $()error +#check: $()items_2_function() +#check: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()items_2_function() +#check: $()Mismatched types. +#nextln: $()expected: u64 +#nextln: $()found: bool. + +#check: $()error +#check: $()fn items_2_trait_function(self, x: TestStruct2) -> u64 { +#nextln: $()expected: bool +#nextln: $()found: u64 + +#check: $()error +#check: $()let items_1_struct = Items1_Struct { a: 123 }; +#nextln: $()Mismatched types. +#nextln: $()expected: bool +#nextln: $()found: numeric. + +#check: $()error +#check: $()let items_1_enum = Items1_Enum::A(432); +#nextln: $()Mismatched types. +#nextln: $()expected: bool +#nextln: $()found: numeric. + +#check: $()error +#check: $()let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); +#nextln: $()Cannot call associated function "items_1_trait_function" as a method. Use associated function syntax instead. + +#check: $()error +#check: $()let items_2_struct = Items2_Struct { b: 879 }; +#nextln: $()Mismatched types. +#nextln: $()expected: bool +#nextln: $()found: numeric. + +#check: $()error +#check: $()let items_2_enum = Items2_Enum::C(246); +#nextln: $()Mismatched types. +#nextln: $()expected: bool +#nextln: $()found: numeric. + +#check: $()error +#check: $()let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); +#nextln: $()Cannot call associated function "items_2_trait_function" as a method. Use associated function syntax instead. + +#check: $()error +#check: $()This path must return a value of type "u64" from function "items_1_trait_function", but it does not. + +#check: $()error +#check: $()This path must return a value of type "u64" from function "items_2_trait_function", but it does not. + +#check: $()Aborting due to 40 errors. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.lock new file mode 100755 index 00000000000..12796c9cfa0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-01E3D9B036D3B866" + +[[package]] +name = "simple_glob_import" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-01E3D9B036D3B866" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.toml new file mode 100755 index 00000000000..e9e0963dbff --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_glob_import" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_2.sw new file mode 100755 index 00000000000..654a63ac267 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_1.sw new file mode 100644 index 00000000000..27a37d85825 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +use ::items_1::Items1_Struct; + +use ::items_1::Items1_Enum; + +use ::items_1::Items1_Variants::X; +use ::items_1::Items1_Variants::Y; + +use ::items_1::ITEMS_1_FUNCTION_RES; + +use ::items_1::items_1_function; + +use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_2.sw new file mode 100644 index 00000000000..85f030aa50f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +use ::items_2::*; + +use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/main.sw new file mode 100755 index 00000000000..57262307323 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/tests.sw new file mode 100644 index 00000000000..acc811144b9 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/src/tests.sw @@ -0,0 +1,126 @@ +library; + +use ::lib_1::*; // Items from items_1.sw not reexported. All imports are item imports +use ::lib_2::*; // Items from items_2.sw not reexported. All imports are glob imports + +use ::items_1::Items1_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.n +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::N(val) => val, + Items2_Enum::M(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + O(val) => val, + P(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { n: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::N(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = O(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/test.toml new file mode 100755 index 00000000000..a17f001163a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_glob_import/test.toml @@ -0,0 +1,129 @@ +category = "fail" + +#check: $()error +#check: $()Could not find symbol "Items1_Struct" in this scope. + +#check: $()error +#check: $()Unknown type name "Items1_Struct" + +#check: $()error +#check: $()Could not find symbol "Items1_Enum" in this scope. + +#check: $()error +#check: $()Unknown type name "Items1_Enum". + +#check: $()error +#check: $()Could not find symbol "X" in this scope. + +#check: $()error +#check: $()Could not find symbol "Y" in this scope. + +#check: $()error +#check: $()Could not find symbol "items_1_function" in this scope. + +#check: $()error +#check: $()Could not find symbol "Items1Trait" in this scope. + +#check: $()error +#check: $()Trait "Items1Trait" cannot be found in the current scope. + +#check: $()error +#check: $()Could not find symbol "Items2_Struct" in this scope. + +#check: $()error +#check: $()Unknown type name "Items2_Struct". + +#check: $()error +#check: $()Could not find symbol "Items2_Enum" in this scope. + +#check: $()error +#check: $()Unknown type name "Items2_Enum". + +#check: $()error +#check: $()Could not find symbol "Items2_Variants" in this scope. + +#check: $()error +#check: $()Unknown type name "Items2_Variants". + +#check: $()error +#check: $()Could not find symbol "items_2_function" in this scope. + +#check: $()error +#check: $()Could not find symbol "Items2Trait" in this scope. + +#check: $()error +#check: $()Trait "Items2Trait" cannot be found in the current scope. + +#check: $()error +#check: $()Could not find symbol "Items1_Struct" in this scope. + +#check: $()error +#check: $()Unknown type name "Items1_Struct". + +#check: $()error +#check: $()Could not find symbol "project_items_1_struct" in this scope. + +#check: $()error +#check: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()Could not find symbol "Items1_Enum" in this scope. + +#check: $()error +#check: $()Unknown type name "Items1_Enum". + +#check: $()error +#check: $()Could not find symbol "project_items_1_enum" in this scope. + +#check: $()error +#check: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()Could not find symbol "X" in this scope. + +#check: $()error +#check: $()Variable "ITEMS_1_FUNCTION_RES" does not exist in this scope. + +#check: $()error +#check: $()No method named "items_1_trait_function" found for type "TestStruct1". + +#check: $()error +#check: $()Could not find symbol "Items2_Struct" in this scope. + +#check: $()error +#check: $()Unknown type name "Items2_Struct". + +#check: $()error +#check: $()Could not find symbol "project_items_2_struct" in this scope. + +#check: $()error +#check: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()Could not find symbol "Items2_Enum" in this scope. + +#check: $()error +#check: $()Unknown type name "Items2_Enum". + +#check: $()error +#check: $()Could not find symbol "project_items_2_enum" in this scope. + +#check: $()error +#check: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()Could not find symbol "O" in this scope. + +#check: $()error +#check: $()Could not find symbol "project_items_2_variants" in this scope. + +#check: $()error +#check: $()No method named "eq" found for type "{unknown}". + +#check: $()error +#check: $()Variable "ITEMS_2_FUNCTION_RES" does not exist in this scope. + +#check: $()error +#check: $()No method named "items_2_trait_function" found for type "TestStruct1". + +#check: $()Aborting due to 42 errors. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.lock new file mode 100755 index 00000000000..3153bd921ae --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-628D42C449EC89D5" + +[[package]] +name = "simple_item_import" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-628D42C449EC89D5" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.toml new file mode 100755 index 00000000000..37dd2996343 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_item_import" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_2.sw new file mode 100755 index 00000000000..654a63ac267 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_3.sw new file mode 100644 index 00000000000..36e1338e4cc --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/items_3.sw @@ -0,0 +1,6 @@ +library; + +pub enum Items3_Variants { + S: u64, + T: u64, +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_1.sw new file mode 100644 index 00000000000..27a37d85825 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +use ::items_1::Items1_Struct; + +use ::items_1::Items1_Enum; + +use ::items_1::Items1_Variants::X; +use ::items_1::Items1_Variants::Y; + +use ::items_1::ITEMS_1_FUNCTION_RES; + +use ::items_1::items_1_function; + +use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_2.sw new file mode 100644 index 00000000000..85f030aa50f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +use ::items_2::*; + +use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_3.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_3.sw new file mode 100644 index 00000000000..f2bb86f118f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/lib_3.sw @@ -0,0 +1,3 @@ +library; + +pub use ::items_3::Items3_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/main.sw new file mode 100755 index 00000000000..57262307323 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/tests.sw new file mode 100644 index 00000000000..dc37866d715 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/src/tests.sw @@ -0,0 +1,158 @@ +library; + + // Reexported items from items_1.sw. All reexports are item imports +use ::lib_1::Items1_Struct; +use ::lib_1::Items1_Enum; +use ::lib_1::X; +use ::lib_1::Y; +use ::lib_1::ITEMS_1_FUNCTION_RES; +use ::lib_1::items_1_function; +use ::lib_1::Items1Trait; + +// Reexported items from items_2.sw. All reexports are glob imports +use ::lib_2::Items2_Struct; +use ::lib_2::Items2_Enum; +use ::lib_2::Items2_Variants; +use ::lib_2::O; +use ::lib_2::P; +use ::lib_2::ITEMS_2_FUNCTION_RES; +use ::lib_2::items_2_function; +use ::lib_2::Items2Trait; + +// Edge case: pub use Enum_name::* should not cause Enum_name::X to be a legal path +use ::lib_3::Items3_Variants::S; + +// Needed to match on Items1_Variants::{X, Y} +use ::items_1::Items1_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.n +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::N(val) => val, + Items2_Enum::M(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + O(val) => val, + P(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + +// lib_3 tests + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + Items3_Variants::S(val) => val, + Items3_Variants::T(val) => val + 1000, + } +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { n: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::N(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = O(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + let items_3_variants = Items3_Variants::S(513); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 513); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/test.toml new file mode 100755 index 00000000000..3e1058ab30e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_item_import/test.toml @@ -0,0 +1,91 @@ +category = "fail" + +#check: $()error +#check: $()use ::lib_1::Items1_Struct; +#nextln: $()Symbol "Items1_Struct" is private. + +#check: $()error +#check: $()use ::lib_1::Items1_Enum; +#nextln: $()Symbol "Items1_Enum" is private. + +#check: $()error +#check: $()use ::lib_1::X; +#nextln: $()Symbol "X" is private. + +#check: $()error +#check: $()use ::lib_1::Y; +#nextln: $()Symbol "Y" is private. + +#check: $()error +#check: $()use ::lib_1::ITEMS_1_FUNCTION_RES; +#nextln: $()Symbol "ITEMS_1_FUNCTION_RES" is private. + +#check: $()error +#check: $()use ::lib_1::items_1_function; +#nextln: $()Symbol "items_1_function" is private. + +#check: $()error +#check: $()use ::lib_1::Items1Trait; +#nextln: $()Symbol "Items1Trait" is private. + +#check: $()error +#check: $()use ::lib_2::Items2_Struct; +#nextln: $()Symbol "Items2_Struct" is private. + +#check: $()error +#check: $()use ::lib_2::Items2_Enum; +#nextln: $()Symbol "Items2_Enum" is private. + +#check: $()error +#check: $()use ::lib_2::Items2_Variants; +#nextln: $()Symbol "Items2_Variants" is private. + +#check: $()error +#check: $()use ::lib_2::O; +#nextln: $()Symbol "O" is private. + +#check: $()error +#check: $()use ::lib_2::P; +#nextln: $()Symbol "P" is private. + +#check: $()error +#check: $()use ::lib_2::ITEMS_2_FUNCTION_RES; +#nextln: $()Symbol "ITEMS_2_FUNCTION_RES" is private. + +#check: $()error +#check: $()use ::lib_2::items_2_function; +#nextln: $()Symbol "items_2_function" is private. + +#check: $()error +#check: $()use ::lib_2::Items2Trait; +#nextln: $()Symbol "Items2Trait" is private. + +#check: $()error +#check: $()use ::lib_3::Items3_Variants::S; +#nextln: $()Module "lib_3::Items3_Variants" could not be found. + +#check: $()error +#check: $()fn project_items_3_variants(input: Items3_Variants) -> u64 { +#nextln: $()Could not find symbol "Items3_Variants" in this scope. + +#check: $()error +#check: $()fn project_items_3_variants(input: Items3_Variants) -> u64 { +#nextln: $()Unknown type name "Items3_Variants". + +#check: $()error +#check: $()let items_3_variants = Items3_Variants::S(513); +#nextln: $()Could not find symbol "Items3_Variants" in this scope. + +#check: $()error +#check: $()let items_3_variants = Items3_Variants::S(513); +#nextln: $()Unknown type name "Items3_Variants". + +#check: $()error +#check: $()let items_3_variants_res = project_items_3_variants(items_3_variants); +#nextln: $()Could not find symbol "project_items_3_variants" in this scope. + +#check: $()error +#check: $()assert(items_3_variants_res == 513); +#nextln: $()No method named "eq" found for type "{unknown}". + +#check: $()Aborting due to 22 errors. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.lock new file mode 100755 index 00000000000..a7cf53ac834 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-F3FE5D74B284BFAB" + +[[package]] +name = "simple_path_access" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-F3FE5D74B284BFAB" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.toml new file mode 100755 index 00000000000..dbc40b43ba1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_path_access" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_2.sw new file mode 100755 index 00000000000..250723123de --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_1.sw new file mode 100644 index 00000000000..27a37d85825 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +use ::items_1::Items1_Struct; + +use ::items_1::Items1_Enum; + +use ::items_1::Items1_Variants::X; +use ::items_1::Items1_Variants::Y; + +use ::items_1::ITEMS_1_FUNCTION_RES; + +use ::items_1::items_1_function; + +use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_2.sw new file mode 100644 index 00000000000..85f030aa50f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +use ::items_2::*; + +use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/main.sw new file mode 100755 index 00000000000..57262307323 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/tests.sw new file mode 100644 index 00000000000..3dcd5515781 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/src/tests.sw @@ -0,0 +1,96 @@ +library; + +// Disabled +// This test is supposed to test that `use` without `pub` makes the item private, +// but the path resolution is broken, so the test doesn't test what it's supposed to test. + +use ::items_1::Items1_Variants; + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +impl ::lib_1::Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +impl ::lib_2::Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + +pub fn run_all_tests() -> u64 { + // lib_1 tests + let items_1_struct = ::lib_1::Items1_Struct { a: 123 }; + assert(items_1_struct.a == 123); + + let items_1_enum = ::lib_1::Items1_Enum::A(432); + let items_1_enum_res = match items_1_enum { + ::items_1::Items1_Enum::A(val) => val, + ::items_1::Items1_Enum::B(val) => val + 1000, + }; + assert(items_1_enum_res == 432); + + // TODO: Should this be allowed? ::lib_1::X refers to ::items_1::Items1_Variants::X. + let items_1_variants = ::lib_1::X(680); + let items_1_variants_res = match items_1_variants { + ::items_1::Items1_Variants::X(val) => val, + ::items_1::Items1_Variants::Y(val) => val + 1000, + }; + assert(items_1_variants_res == 680); + + let items_1_function_res = ::lib_1::items_1_function(); + let items_1_function_oracle = ::lib_1::ITEMS_1_FUNCTION_RES; + assert(items_1_function_res == items_1_function_oracle); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + // lib_2 tests + + let items_2_struct = ::lib_2::Items2_Struct { n: 789 }; + assert(items_2_struct.n == 789); + + let items_2_enum = ::lib_2::Items2_Enum::N(246); + let items_2_enum_res = match items_2_enum { + ::items_2::Items2_Enum::N(val) => val, + ::items_2::Items2_Enum::M(val) => val + 1000, + }; + assert(items_2_enum_res == 246); + + let items_2_variants = ::lib_2::O(468); + let items_2_variants_res = match items_2_variants { + ::items_2::Items2_Variants::O(val) => val, + ::items_2::Items2_Variants::P(val) => val + 1000, + }; + assert(items_2_variants_res == 468); + + let items_2_function_res = ::lib_2::call_items_2_function(); + let items_2_function_oracle = ::lib_2::ITEMS_2_FUNCTION_RES; + assert(items_2_function_res == items_2_function_oracle); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/test.toml new file mode 100755 index 00000000000..5256044dda0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/language/reexport/simple_path_access/test.toml @@ -0,0 +1,4 @@ +category = "disabled" +expected_warnings = 0 + +#not: $()error \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.lock new file mode 100755 index 00000000000..2f79b915015 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "aliases" +source = "member" +dependencies = ["std"] + +[[package]] +name = "core" +source = "path+from-root-D05BA88A39195D06" + +[[package]] +name = "std" +source = "path+from-root-D05BA88A39195D06" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.toml new file mode 100755 index 00000000000..5e3bdd0c704 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "aliases" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_2.sw new file mode 100755 index 00000000000..1fa9465b0ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub enum Items2_Variants { + Z: u64, + W: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_3.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_3.sw new file mode 100755 index 00000000000..cbc06d1bdc4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_3.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: u64, +} + +pub enum Items3_Enum { + E: u64, + F: u64, +} + +pub enum Items3_Variants { + U: u64, + V: u64, +} + +pub const ITEMS_3_FUNCTION_RES = 13278; + +pub fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_4.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_4.sw new file mode 100755 index 00000000000..809d49cc952 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/items_4.sw @@ -0,0 +1,21 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + G: u64, + H: u64, +} + +pub enum Items4_Variants { + S: u64, + T: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 14278; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_1.sw new file mode 100644 index 00000000000..d40aca7a5f1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct as Alias1_Struct; + +pub use ::items_1::Items1_Enum as Alias1_Enum; + +pub use ::items_1::Items1_Variants::X as Alias1_X; +pub use ::items_1::Items1_Variants::Y as Alias1_Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES as ALIAS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function as alias_1_function; + +pub use ::items_1::Items1Trait as Alias1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_2.sw new file mode 100644 index 00000000000..26b2411e634 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_2::Items2_Struct as Alias2_Struct; + +pub use ::items_2::Items2_Enum as Alias2_Enum; + +pub use ::items_2::Items2_Variants::Z as Alias2_Z; +pub use ::items_2::Items2_Variants::W as Alias2_W; + +pub use ::items_2::ITEMS_2_FUNCTION_RES as ALIAS_2_FUNCTION_RES; + +pub use ::items_2::items_2_function as alias_2_function; + +pub use ::items_2::Items2Trait as Alias2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_1.sw new file mode 100644 index 00000000000..9476211085e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_3::Items3_Struct as Alias3_Struct; + +pub use ::items_3::Items3_Enum as Alias3_Enum; + +pub use ::items_3::Items3_Variants::U as Alias3_U; +pub use ::items_3::Items3_Variants::V as Alias3_V; + +pub use ::items_3::ITEMS_3_FUNCTION_RES as ALIAS_3_FUNCTION_RES; + +pub use ::items_3::items_3_function as alias_3_function; + +pub use ::items_3::Items3Trait as Alias3Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_2.sw new file mode 100644 index 00000000000..c6d2e169293 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_3_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::lib_3_1::Alias3_Struct as AltAlias3_Struct; + +pub use ::lib_3_1::Alias3_Enum as AltAlias3_Enum; + +pub use ::lib_3_1::Alias3_U as AltAlias3_U; +pub use ::lib_3_1::Alias3_V as AltAlias3_V; + +pub use ::lib_3_1::ALIAS_3_FUNCTION_RES as ALTALIAS_3_FUNCTION_RES; + +pub use ::lib_3_1::alias_3_function as altalias_3_function; + +pub use ::lib_3_1::Alias3Trait as AltAlias3Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_1.sw new file mode 100644 index 00000000000..49a2fd95803 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_1.sw @@ -0,0 +1,12 @@ +library; + +pub use ::items_4::Items4_Struct as Alias4_Struct; + +pub use ::items_4::Items4_Enum as Alias4_Enum; + +pub use ::items_4::Items4_Variants::S as Alias4_S; +pub use ::items_4::Items4_Variants::T as Alias4_T; + +pub use ::items_4::ITEMS_4_FUNCTION_RES as ALIAS_4_FUNCTION_RES; + +pub use ::items_4::items_4_function as alias_4_function; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_2.sw new file mode 100644 index 00000000000..9ccad36059d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/lib_4_2.sw @@ -0,0 +1,12 @@ +library; + +pub use ::items_4::Items4_Struct as AltAlias4_Struct; + +pub use ::items_4::Items4_Enum as AltAlias4_Enum; + +pub use ::items_4::Items4_Variants::S as AltAlias4_S; +pub use ::items_4::Items4_Variants::T as AltAlias4_T; + +pub use ::items_4::ITEMS_4_FUNCTION_RES as ALTALIAS_4_FUNCTION_RES; + +pub use ::items_4::items_4_function as alt_alias_4_function; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/main.sw new file mode 100755 index 00000000000..18a842fa725 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/main.sw @@ -0,0 +1,18 @@ +script; + +mod items_1; +mod lib_1; // Aliased item reexports of items_1 +mod items_2; +mod lib_2; // Aliased item reexports of items_2 +mod items_3; +mod lib_3_1; // Aliased item reexports of items_3 +mod lib_3_2; // Aliased item reexports of lib_3_1 +mod items_4; +mod lib_4_1; // Aliased item reexports of items_4 +mod lib_4_2; // Aliased item reexports of items_4 with different aliases + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/tests.sw new file mode 100644 index 00000000000..4e3b3e466b4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/src/tests.sw @@ -0,0 +1,253 @@ +library; + + // Reexported items from items_1.sw. All reexports aliased by lib_1 +use ::lib_1::Alias1_Struct; +use ::lib_1::Alias1_Enum; +use ::lib_1::Alias1_X; +use ::lib_1::Alias1_Y; +use ::lib_1::ALIAS_1_FUNCTION_RES; +use ::lib_1::alias_1_function; +use ::lib_1::Alias1Trait; + +use ::items_1::Items1_Variants; + +// Reexported items from items_2.sw. All reexports aliased by lib_2 +use ::lib_2::*; + +use ::items_2::Items2_Variants; + +// Reexported items from items_3.sw. All reexports aliased by lib_3_1 and then by lib_3_2 +use ::lib_3_2::*; + +use ::items_3::Items3_Variants; + +// Reexported items from items_4.sw. All items are reexported and aliased by lib_4_1 and by lib_4_2 using different aliases. +use ::lib_4_1::*; +use ::lib_4_2::*; + +use ::items_4::Items4_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Alias1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Alias1_Enum) -> u64 { + match input { + Alias1_Enum::A(val) => val, + Alias1_Enum::B(val) => val + 1000, + } +} + +// Aliased enum variants are not recognized as belonging to the enum they're coming from, +// so this test is disabled +//fn project_items_1_variants(input: Items1_Variants) -> u64 { +// match input { +// Alias1_X(val) => val, +// Alias1_Y(val) => val + 1000, +// } +//} + +fn call_items_1_function() -> u64 { + alias_1_function() +} + +impl Alias1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Alias2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Alias2_Enum) -> u64 { + match input { + Alias2_Enum::C(val) => val, + Alias2_Enum::D(val) => val + 1000, + } +} + +// Aliased enum variants are not recognized as belonging to the enum they're coming from, +// so this test is disabled +//fn project_items_2_variants(input: Items2_Variants) -> u64 { +// match input { +// Alias2_Z(val) => val, +// Alias2_W(val) => val + 1000, +// } +//} + +fn call_items_2_function() -> u64 { + alias_2_function() +} + +impl Alias2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_3 tests + +fn project_items_3_struct(input: AltAlias3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: AltAlias3_Enum) -> u64 { + match input { + AltAlias3_Enum::E(val) => val, + AltAlias3_Enum::F(val) => val + 1000, + } +} + +// Aliased enum variants are not recognized as belonging to the enum they're coming from, +// so this test is disabled +//fn project_items_3_variants(input: Items3_Variants) -> u64 { +// match input { +// AltAlias3_U(val) => val, +// AltAlias3_V(val) => val + 1000, +// } +//} + +fn call_items_3_function() -> u64 { + altalias_3_function() +} + +impl AltAlias3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_4 tests + +fn project_items_4_struct(input: AltAlias4_Struct) -> u64 { + input.d +} + +fn project_items_4_enum(input: Alias4_Enum) -> u64 { + match input { + Alias4_Enum::G(val) => val, + AltAlias4_Enum::H(val) => val + 1000, + } +} + +// Aliased enum variants are not recognized as belonging to the enum they're coming from, +// so this test is disabled +//fn project_items_4_variants(input: Items4_Variants) -> u64 { +// match input { +// Alias4_S(val) => val, +// AltAlias4_T(val) => val + 1000, +// } +//} + +fn call_items_4_function() -> u64 { + alias_4_function() + alt_alias_4_function() +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Alias1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Alias1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + +// Alias1_X is recognized as an alias, but it's still impossible to construct a value using Alias1_X +// let items_1_variants = Alias1_X(680); +// let items_1_variants_res = project_items_1_variants(items_1_variants); +// assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ALIAS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Alias2_Struct { b: 123 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 123); + + let items_2_enum = Alias2_Enum::C(432); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 432); + + // Alias2_Z is recognized as an alias, but it's still impossible to construct a value using Alias2_Z +// let items_2_variants = Alias2_Z(680); +// let items_2_variants_res = project_items_2_variants(items_2_variants); +// assert(items_2_variants_res == 680); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ALIAS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + + let items_3_struct = AltAlias3_Struct { c: 123 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 123); + + let items_3_enum = AltAlias3_Enum::E(432); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 432); + + // AltAlias3_U is recognized as an alias, but it's still impossible to construct a value using AltAlias3_U +// let items_3_variants = AltAlias3_U(680); +// let items_3_variants_res = project_items_3_variants(items_3_variants); +// assert(items_3_variants_res == 680); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ALTALIAS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res); + + + let items_4_struct = AltAlias4_Struct { d: 123 }; + let items_4_struct_res = project_items_4_struct(items_4_struct); + assert(items_4_struct_res == 123); + + let items_4_enum = AltAlias4_Enum::G(432); + let items_4_enum_res = project_items_4_enum(items_4_enum); + assert(items_4_enum_res == 432); + + // AltAlias4_S is recognized as an alias, but it's still impossible to construct a value using AltAlias4_S +// let items_4_variants = AltAlias4_S(680); +// let items_4_variants_res = project_items_4_variants(items_4_variants); +// assert(items_4_variants_res == 680); + + let items_4_function_res = call_items_4_function(); + assert(items_4_function_res == ALTALIAS_4_FUNCTION_RES * 2); + + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/test.toml new file mode 100755 index 00000000000..5b7635b072b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/aliases/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 7 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.lock new file mode 100755 index 00000000000..d59e66c3300 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-5E33A7D67412F1BB" + +[[package]] +name = "multiple_imports_of_same_reexport" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-5E33A7D67412F1BB" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.toml new file mode 100755 index 00000000000..06785d8428a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "multiple_imports_of_same_reexport" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_2.sw new file mode 100755 index 00000000000..1fa9465b0ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub enum Items2_Variants { + Z: u64, + W: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_3.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_3.sw new file mode 100644 index 00000000000..40359c434ad --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_3.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: u64, +} + +pub enum Items3_Enum { + E: u64, + F: u64, +} + +pub enum Items3_Variants { + U: u64, + V: u64, +} + +pub const ITEMS_3_FUNCTION_RES = 1111; + +pub fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_4.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_4.sw new file mode 100644 index 00000000000..2d93dc802f4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/items_4.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + G: u64, + H: u64, +} + +pub enum Items4_Variants { + S: u64, + T: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 5325; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_1_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_1.sw new file mode 100644 index 00000000000..8689296a943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_1.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_2::*; + +pub use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_2.sw new file mode 100644 index 00000000000..8689296a943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_2_2.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_2::*; + +pub use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_1.sw new file mode 100644 index 00000000000..b5955209281 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_1.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_3::*; + +pub use ::items_3::Items3_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_2.sw new file mode 100644 index 00000000000..0bc3e96a689 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_3_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_3::Items3_Struct; + +pub use ::items_3::Items3_Enum; + +pub use ::items_3::Items3_Variants::U; +pub use ::items_3::Items3_Variants::V; + +pub use ::items_3::ITEMS_3_FUNCTION_RES; + +pub use ::items_3::items_3_function; + +pub use ::items_3::Items3Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_1.sw new file mode 100644 index 00000000000..2c2c70401b6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_4::Items4_Struct; + +pub use ::items_4::Items4_Enum; + +pub use ::items_4::Items4_Variants::S; +pub use ::items_4::Items4_Variants::T; + +pub use ::items_4::ITEMS_4_FUNCTION_RES; + +pub use ::items_4::items_4_function; + +pub use ::items_4::Items4Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_2.sw new file mode 100644 index 00000000000..ba688f2f755 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/lib_4_2.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_4::*; + +pub use ::items_4::Items4_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/main.sw new file mode 100755 index 00000000000..4ae46fbab15 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/main.sw @@ -0,0 +1,20 @@ +script; + +mod items_1; +mod lib_1_1; // Item reexports of items_1 +mod lib_1_2; // Item reexports of items_1 +mod items_2; +mod lib_2_1; // Star reexports of items_2 +mod lib_2_2; // Star reexports of items_2 +mod items_3; +mod lib_3_1; // Star reexports of items_3 +mod lib_3_2; // Item reexports of items_3 +mod items_4; +mod lib_4_1; // Item reexports of items_4 +mod lib_4_2; // Star reexports of items_4 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/tests.sw new file mode 100644 index 00000000000..c1058c32671 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/src/tests.sw @@ -0,0 +1,243 @@ +library; + +// Both lib_1_1.sw and lib_1_2.sw reexport items from items_1.sw. All reexports are item imports. +// Importing both lib_1_1 and lib_1_2 should not cause a name clash. +use ::lib_1_1::*; +use ::lib_1_2::*; +// Both lib_2_1.sw and lib_2_2.sw reexport items from items_2.sw. All reexports are star imports. +// Importing both lib_2_1 and lib_2_2 should not cause a name clash. +use ::lib_2_1::*; +use ::lib_2_2::*; +// Both lib_3_1.sw and lib_3_2.sw reexport items from items_3.sw. lib_3_1 star reexports, lib_3_2 +// item reexports. Importing both lib_3_1 and lib_3_2 should not cause a name clash. +use ::lib_3_1::*; +use ::lib_3_2::*; +// Both lib_4_1.sw and lib_4_2.sw reexport items from items_4.sw. lib_4_1 item reexports, lib_4_2 +// star reexports. Importing both lib_4_1 and lib_4_2 should not cause a name clash. +// This tests that ordering of imports do not matter. +use ::lib_4_1::*; +use ::lib_4_2::*; + +use ::items_1::Items1_Variants; +use ::items_2::Items2_Variants; +use ::items_3::Items3_Variants; +use ::items_4::Items4_Variants; + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + +// items_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + +// items_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::C(val) => val, + Items2_Enum::D(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + Z(val) => val, + W(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + +// items_3 tests + +fn project_items_3_struct(input: Items3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: Items3_Enum) -> u64 { + match input { + Items3_Enum::E(val) => val, + Items3_Enum::F(val) => val + 1000, + } +} + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + U(val) => val, + V(val) => val + 1000, + } +} + +fn call_items_3_function() -> u64 { + items_3_function() +} + +impl Items3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> bool { + self.Z == 122 && x.W + } +} + +// items_4 tests + +fn project_items_4_struct(input: Items4_Struct) -> u64 { + input.d +} + +fn project_items_4_enum(input: Items4_Enum) -> u64 { + match input { + Items4_Enum::G(val) => val, + Items4_Enum::H(val) => val + 1000, + } +} + +fn project_items_4_variants(input: Items4_Variants) -> u64 { + match input { + S(val) => val, + T(val) => val + 1000, + } +} + +fn call_items_4_function() -> u64 { + items_4_function() +} + +impl Items4Trait for TestStruct1 { + fn items_4_trait_function(self, x: TestStruct2) -> bool { + self.Z == 122 && x.W + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { b: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::C(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = Z(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + + let items_3_struct = Items3_Struct { c: 789 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 789); + + let items_3_enum = Items3_Enum::E(246); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 246); + + let items_3_variants = U(468); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 468); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ITEMS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 122 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res); + + + let items_4_struct = Items4_Struct { d: 789 }; + let items_4_struct_res = project_items_4_struct(items_4_struct); + assert(items_4_struct_res == 789); + + let items_4_enum = Items4_Enum::G(246); + let items_4_enum_res = project_items_4_enum(items_4_enum); + assert(items_4_enum_res == 246); + + let items_4_variants = S(468); + let items_4_variants_res = project_items_4_variants(items_4_variants); + assert(items_4_variants_res == 468); + + let items_4_function_res = call_items_4_function(); + assert(items_4_function_res == ITEMS_4_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 122 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_4_trait_teststruct_1_res = teststruct_1.items_4_trait_function(teststruct_2); + assert(items_4_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/test.toml new file mode 100755 index 00000000000..0b73866a32b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/multiple_imports_of_same_reexport/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 1 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.lock new file mode 100755 index 00000000000..5238fc6cfc4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-CE974A175C1B7D31" + +[[package]] +name = "reexport_paths" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-CE974A175C1B7D31" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.toml new file mode 100755 index 00000000000..5d787dce6ac --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "reexport_paths" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_1.sw new file mode 100644 index 00000000000..9d3a4594442 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_1.sw @@ -0,0 +1,4 @@ +library; + +pub use ::items_1::*; +pub use ::items_1::Items1_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_2.sw new file mode 100644 index 00000000000..a1de8f9d9de --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_1_2.sw @@ -0,0 +1,4 @@ +library; + +pub use ::lib_1_1::*; +pub use ::lib_1_1::Items1_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_2.sw new file mode 100644 index 00000000000..a298d9f1943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_2.sw @@ -0,0 +1,3 @@ +library; + +pub use std::hash::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_1.sw new file mode 100644 index 00000000000..e6bfbe13e7b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_1.sw @@ -0,0 +1,4 @@ +library; + +pub use std::ecr::EcRecoverError; + diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_2.sw new file mode 100644 index 00000000000..00d14947ef8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_3_2.sw @@ -0,0 +1,3 @@ +library; + +pub use std::ecr::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_4.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_4.sw new file mode 100644 index 00000000000..462edd378e7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_4.sw @@ -0,0 +1,3 @@ +library; + +pub use std::registers::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_5.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_5.sw new file mode 100644 index 00000000000..b5031e1af4e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_5.sw @@ -0,0 +1,3 @@ +library; + +pub use core::codec::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_1.sw new file mode 100644 index 00000000000..41f4c8609f4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_1.sw @@ -0,0 +1,3 @@ +library; + +pub use std::prelude::Address; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_2.sw new file mode 100644 index 00000000000..69dc48f1dd2 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/lib_6_2.sw @@ -0,0 +1,3 @@ +library; + +pub use std::address::Address; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/main.sw new file mode 100755 index 00000000000..84a4dffa3df --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/main.sw @@ -0,0 +1,18 @@ +script; + +mod items_1; +mod lib_1_1; // Reexports of items_1 +mod lib_1_2; // Reexports of lib_1_1 +mod lib_2; // Reexports of std::hash::Hasher, which is not part of the std prelude +mod lib_3_1; // Reexports of std::hash::Hash, which is not part of the std prelude +mod lib_3_2; // Reexports of std::hash::Hash, which is not part of the std prelude +mod lib_4; // Reexport of std::registers::global_gas +mod lib_5; // Reexport of core::codec::* +//mod lib_6_1; // Reexports of std::address::Address from the std prelude +mod lib_6_2; // Reexports of std::address::Address directly from std::address + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/tests.sw new file mode 100644 index 00000000000..453221c03ba --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/src/tests.sw @@ -0,0 +1,140 @@ +library; + +// Items from items_1.sw reexported via lib_1_1 and lib_1_2. +use ::lib_1_2::*; +// Reexport of std::hash::*, which is not part of the std prelude. +use ::lib_2::*; +// Reexports of std::ecr::EcRecoverError, which is not part of the std prelude. +use ::lib_3_1::*; +use ::lib_3_2::*; +// Reexport of std::registers::*, which is not part of the std prelude. +use ::lib_4::global_gas; +// Reexport of core::codec::*, which is part of the std prelude. +use ::lib_5::Buffer; +// Reexports of std::address::Address, one via std::prelude and one directly from std::address +// Importing from std::prelude causes an error, so that part of the test is disabled for now. +//use ::lib_6_1::*; +use ::lib_6_2::*; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn mk_hasher() -> Hasher { + Hasher::new() +} + +impl Hash for TestStruct1 { + fn hash(self, ref mut _state: Hasher) { + } +} + + +// lib_3 tests + +fn mk_ec_recover_error() -> EcRecoverError { + EcRecoverError::UnrecoverablePublicKey +} + + +// lib_4 tests + +fn get_global_gas() -> u64 { + global_gas() +} + + +// lib_5 tests + +fn mk_buffer() -> Buffer { + Buffer::new() +} + + +// lib_6 tests + +fn mk_address() -> Address { + Address::zero() +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let hasher = mk_hasher(); + teststruct_1.hash(hasher); + + + let _ = mk_ec_recover_error(); + + + let _ = get_global_gas(); + + + let _ = mk_buffer(); + + + let _ = mk_address(); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/test.toml new file mode 100755 index 00000000000..5341fe8486c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 0 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.lock new file mode 100644 index 00000000000..72fcfaba5ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.lock @@ -0,0 +1,76 @@ +[[package]] +name = "core" +source = "path+from-root-43D7B7046829C73F" + +[[package]] +name = "ext_1_items" +source = "member" + +[[package]] +name = "ext_1_lib" +source = "member" +dependencies = ["ext_1_items"] + +[[package]] +name = "ext_2_items" +source = "member" + +[[package]] +name = "ext_2_lib" +source = "member" +dependencies = ["ext_2_items"] + +[[package]] +name = "ext_3_items" +source = "member" + +[[package]] +name = "ext_3_lib" +source = "member" +dependencies = ["ext_3_items"] + +[[package]] +name = "ext_4_items" +source = "member" + +[[package]] +name = "ext_4_lib" +source = "member" +dependencies = ["ext_4_items"] + +[[package]] +name = "ext_5_1_lib" +source = "member" +dependencies = ["ext_5_items"] + +[[package]] +name = "ext_5_2_lib" +source = "member" +dependencies = ["ext_5_items"] + +[[package]] +name = "ext_5_items" +source = "member" + +[[package]] +name = "program" +source = "member" +dependencies = [ + "ext_1_items", + "ext_1_lib", + "ext_2_items", + "ext_2_lib", + "ext_3_items", + "ext_3_lib", + "ext_4_items", + "ext_4_lib", + "ext_5_1_lib", + "ext_5_2_lib", + "ext_5_items", + "std", +] + +[[package]] +name = "std" +source = "path+from-root-43D7B7046829C73F" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.toml new file mode 100644 index 00000000000..6bb836d1178 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/Forc.toml @@ -0,0 +1,14 @@ +[workspace] +members = ["program", + "ext_1_items", + "ext_1_lib", + "ext_2_items", + "ext_2_lib", + "ext_3_items", + "ext_3_lib", + "ext_4_items", + "ext_4_lib", + "ext_5_items", + "ext_5_1_lib", + "ext_5_2_lib", + ] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/Forc.toml new file mode 100644 index 00000000000..12da0871200 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_1_items" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/src/lib.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_items/src/lib.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/Forc.toml new file mode 100644 index 00000000000..2230a157aad --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_1_lib" +implicit-std = false + +[dependencies] +ext_1_items = { path = "../ext_1_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/src/lib.sw new file mode 100644 index 00000000000..152e4e004b3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_1_lib/src/lib.sw @@ -0,0 +1,14 @@ +library; + +pub use ext_1_items::Items1_Struct; + +pub use ext_1_items::Items1_Enum; + +pub use ext_1_items::Items1_Variants::X; +pub use ext_1_items::Items1_Variants::Y; + +pub use ext_1_items::ITEMS_1_FUNCTION_RES; + +pub use ext_1_items::items_1_function; + +pub use ext_1_items::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/Forc.toml new file mode 100644 index 00000000000..fb9c571f29e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_2_items" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/src/lib.sw new file mode 100644 index 00000000000..3802e175e76 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_items/src/lib.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub enum Items2_Variants { + Z: u64, + W: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 324; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/Forc.toml new file mode 100644 index 00000000000..711c4baf383 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_2_lib" +implicit-std = false + +[dependencies] +ext_2_items = { path = "../ext_2_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/src/lib.sw new file mode 100644 index 00000000000..4f7c5f4d30d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_2_lib/src/lib.sw @@ -0,0 +1,4 @@ +library; + +pub use ext_2_items::*; +pub use ext_2_items::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/Forc.toml new file mode 100644 index 00000000000..a04f49ceead --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_3_items" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/src/lib.sw new file mode 100644 index 00000000000..4d61d81be80 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_items/src/lib.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: u64, +} + +pub enum Items3_Enum { + E: u64, + F: u64, +} + +pub enum Items3_Variants { + U: u64, + V: u64, +} + +pub const ITEMS_3_FUNCTION_RES = 893; + +pub fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/Forc.toml new file mode 100644 index 00000000000..56967137a18 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_3_lib" +implicit-std = false + +[dependencies] +ext_3_items = { path = "../ext_3_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/src/lib.sw new file mode 100644 index 00000000000..79e79fb09d5 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_3_lib/src/lib.sw @@ -0,0 +1,14 @@ +library; + +pub use ext_3_items::Items3_Struct; + +pub use ext_3_items::Items3_Enum; + +pub use ext_3_items::Items3_Variants::U; +pub use ext_3_items::Items3_Variants::V; + +pub use ext_3_items::ITEMS_3_FUNCTION_RES; + +pub use ext_3_items::items_3_function; + +pub use ext_3_items::Items3Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/Forc.toml new file mode 100644 index 00000000000..555024e8f6c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_4_items" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/src/lib.sw new file mode 100644 index 00000000000..740942a391a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_items/src/lib.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + G: u64, + H: u64, +} + +pub enum Items4_Variants { + S: u64, + T: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 2389; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/Forc.toml new file mode 100644 index 00000000000..bbb8b468d40 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_4_lib" +implicit-std = false + +[dependencies] +ext_4_items = { path = "../ext_4_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/src/lib.sw new file mode 100644 index 00000000000..8084e777a58 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_4_lib/src/lib.sw @@ -0,0 +1,4 @@ +library; + +pub use ext_4_items::*; +pub use ext_4_items::Items4_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/Forc.toml new file mode 100644 index 00000000000..db6f8a3fdf8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_5_1_lib" +implicit-std = false + +[dependencies] +ext_5_items = { path = "../ext_5_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/src/lib.sw new file mode 100644 index 00000000000..eafc9dea600 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_1_lib/src/lib.sw @@ -0,0 +1,4 @@ +library; + +pub use ext_5_items::*; +pub use ext_5_items::Items5_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/Forc.toml new file mode 100644 index 00000000000..03e87b6ca67 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_5_2_lib" +implicit-std = false + +[dependencies] +ext_5_items = { path = "../ext_5_items/" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/src/lib.sw new file mode 100644 index 00000000000..eafc9dea600 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_2_lib/src/lib.sw @@ -0,0 +1,4 @@ +library; + +pub use ext_5_items::*; +pub use ext_5_items::Items5_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/Forc.toml new file mode 100644 index 00000000000..403f3fb061e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/Forc.toml @@ -0,0 +1,6 @@ +[project] +authors = ["Fuel Labs "] +entry = "lib.sw" +license = "Apache-2.0" +name = "ext_5_items" +implicit-std = false diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/src/lib.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/src/lib.sw new file mode 100644 index 00000000000..b8bd79e4559 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/ext_5_items/src/lib.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items5_Struct { + pub e: u64, +} + +pub enum Items5_Enum { + I: u64, + J: u64, +} + +pub enum Items5_Variants { + Q: u64, + R: u64, +} + +pub const ITEMS_5_FUNCTION_RES = 32894; + +pub fn items_5_function() -> u64 { + ITEMS_5_FUNCTION_RES +} + +pub trait Items5Trait { + fn items_5_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/Forc.toml new file mode 100755 index 00000000000..56fc83c4f7d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/Forc.toml @@ -0,0 +1,20 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "program" +implicit-std = false + +[dependencies] +ext_1_items = { path = "../ext_1_items/" } +ext_1_lib = { path = "../ext_1_lib/" } +ext_2_items = { path = "../ext_2_items/" } +ext_2_lib = { path = "../ext_2_lib/" } +ext_3_items = { path = "../ext_3_items/" } +ext_3_lib = { path = "../ext_3_lib/" } +ext_4_items = { path = "../ext_4_items/" } +ext_4_lib = { path = "../ext_4_lib/" } +ext_5_items = { path = "../ext_5_items/" } +ext_5_1_lib = { path = "../ext_5_1_lib/" } +ext_5_2_lib = { path = "../ext_5_2_lib/" } +std = { path = "../../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/main.sw new file mode 100755 index 00000000000..bcc453959df --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/main.sw @@ -0,0 +1,7 @@ +script; + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/tests.sw new file mode 100644 index 00000000000..5670d3deaa3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/program/src/tests.sw @@ -0,0 +1,310 @@ +library; + +// Reexported items from ext_1_items. All reexports are item imports. +use ext_1_lib::*; +use ext_1_items::Items1_Variants; +// Reexported items from ext_2_items. All reexports are star imports. +use ext_2_lib::*; +// Reexported items from ext_3_items. All reexports are item imports. +use ext_3_lib::Items3_Struct; +use ext_3_lib::Items3_Enum; +// ext_3_lib elevates U and V to the same namespace as the type names, so Items3_Variants cannot be found in ext_3_lib. +//use ext_3_lib::Items3_Variants::U; +//use ext_3_lib::Items3_Variants::V; +use ext_3_lib::U; +use ext_3_lib::V; +use ext_3_lib::ITEMS_3_FUNCTION_RES; +use ext_3_lib::items_3_function; +use ext_3_lib::Items3Trait; +use ext_3_items::Items3_Variants; +// Reexported items from ext_4_items. All reexports are star imports. +use ext_4_lib::Items4_Struct; +use ext_4_lib::Items4_Enum; +// ext_4_lib elevates S and T to the same namespace as the type names, so Items4_Variants cannot be found in ext_4_lib. +//use ext_4_lib::Items4_Variants::S; +//use ext_4_lib::Items4_Variants::T; +use ext_4_lib::S; +use ext_4_lib::T; +use ext_4_lib::ITEMS_4_FUNCTION_RES; +use ext_4_lib::items_4_function; +use ext_4_lib::Items4Trait; +use ext_4_items::Items4_Variants; +// Reexported items from ext_5_items through two libraries. +use ext_5_1_lib::*; +use ext_5_2_lib::*; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// ext_1_lib tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// ext_2_lib tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::C(val) => val, + Items2_Enum::D(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + Z(val) => val, + W(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// ext_3_lib tests + +fn project_items_3_struct(input: Items3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: Items3_Enum) -> u64 { + match input { + Items3_Enum::E(val) => val, + Items3_Enum::F(val) => val + 1000, + } +} + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + U(val) => val, + V(val) => val + 1000, + } +} + +fn call_items_3_function() -> u64 { + items_3_function() +} + +impl Items3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// ext_4_lib tests + +fn project_items_4_struct(input: Items4_Struct) -> u64 { + input.d +} + +fn project_items_4_enum(input: Items4_Enum) -> u64 { + match input { + Items4_Enum::G(val) => val, + Items4_Enum::H(val) => val + 1000, + } +} + +fn project_items_4_variants(input: Items4_Variants) -> u64 { + match input { + S(val) => val, + T(val) => val + 1000, + } +} + +fn call_items_4_function() -> u64 { + items_4_function() +} + +impl Items4Trait for TestStruct1 { + fn items_4_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// ext_5_lib tests + +fn project_items_5_struct(input: Items5_Struct) -> u64 { + input.e +} + +fn project_items_5_enum(input: Items5_Enum) -> u64 { + match input { + Items5_Enum::I(val) => val, + Items5_Enum::J(val) => val + 1000, + } +} + +fn project_items_5_variants(input: Items5_Variants) -> u64 { + match input { + Q(val) => val, + R(val) => val + 1000, + } +} + +fn call_items_5_function() -> u64 { + items_5_function() +} + +impl Items5Trait for TestStruct1 { + fn items_5_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { b: 223 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 223); + + let items_2_enum = Items2_Enum::C(432); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 432); + + let items_2_variants = Z(680); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 680); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + + let items_3_struct = Items3_Struct { c: 323 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 323); + + let items_3_enum = Items3_Enum::E(432); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 432); + + let items_3_variants = U(680); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 680); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ITEMS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res); + + + let items_4_struct = Items4_Struct { d: 424 }; + let items_4_struct_res = project_items_4_struct(items_4_struct); + assert(items_4_struct_res == 424); + + let items_4_enum = Items4_Enum::G(442); + let items_4_enum_res = project_items_4_enum(items_4_enum); + assert(items_4_enum_res == 442); + + let items_4_variants = S(680); + let items_4_variants_res = project_items_4_variants(items_4_variants); + assert(items_4_variants_res == 680); + + let items_4_function_res = call_items_4_function(); + assert(items_4_function_res == ITEMS_4_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_4_trait_teststruct_1_res = teststruct_1.items_4_trait_function(teststruct_2); + assert(items_4_trait_teststruct_1_res); + + + let items_5_struct = Items5_Struct { e: 525 }; + let items_5_struct_res = project_items_5_struct(items_5_struct); + assert(items_5_struct_res == 525); + + let items_5_enum = Items5_Enum::I(552); + let items_5_enum_res = project_items_5_enum(items_5_enum); + assert(items_5_enum_res == 552); + + let items_5_variants = Q(680); + let items_5_variants_res = project_items_5_variants(items_5_variants); + assert(items_5_variants_res == 680); + + let items_5_function_res = call_items_5_function(); + assert(items_5_function_res == ITEMS_5_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_5_trait_teststruct_1_res = teststruct_1.items_5_trait_function(teststruct_2); + assert(items_5_trait_teststruct_1_res); + + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/test.toml new file mode 100644 index 00000000000..2c5bf1ae09a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/reexport_paths_external_lib/test.toml @@ -0,0 +1,2 @@ +category = "compile" +expected_warnings = 0 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.lock new file mode 100755 index 00000000000..ac25cb26c8e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-EE202EE2D1735C08" + +[[package]] +name = "shadowing_in_reexporting_module" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-EE202EE2D1735C08" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.toml new file mode 100755 index 00000000000..4b87dd678a8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "shadowing_in_reexporting_module" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_1.sw new file mode 100644 index 00000000000..95b236919b7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_1.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items1_Struct { + pub a: bool, +} + +pub enum Items1_Enum { + A: bool, + B: bool, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> bool { + ITEMS_1_FUNCTION_RES == 456 +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw new file mode 100644 index 00000000000..f00aa5f00c7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_1.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items2_Struct { + pub b: bool, +} + +pub enum Items2_Enum { + C: bool, + D: bool, +} + +pub const ITEMS_2_FUNCTION_RES = 789; + +pub fn items_2_function() -> bool { + ITEMS_2_FUNCTION_RES == 789 +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw new file mode 100644 index 00000000000..6822e86d865 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_2_2.sw @@ -0,0 +1,20 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw new file mode 100644 index 00000000000..86138d9e3ed --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_3_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items3_Struct { + pub c: bool, +} + +pub enum Items3_Enum { + E: bool, + F: bool, +} + +pub enum Items3_Variants { + G: bool, + H: bool, +} + +pub const ITEMS_3_FUNCTION_RES = 1234; + +pub fn items_3_function() -> bool { + ITEMS_3_FUNCTION_RES == 1234 +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw new file mode 100644 index 00000000000..2d9be57fc13 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: bool, +} + +pub enum Items4_Enum { + I: bool, + J: bool, +} + +pub enum Items4_Variants { + K: bool, + L: bool, +} + +pub const ITEMS_4_FUNCTION_RES = 5678; + +pub fn items_4_function() -> bool { + ITEMS_4_FUNCTION_RES == 5678 +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw new file mode 100644 index 00000000000..d57d5b3fbc6 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items4_Struct { + pub d: u64, +} + +pub enum Items4_Enum { + I: u64, + J: u64, +} + +pub enum Items4_Variants { + K: u64, + L: u64, +} + +pub const ITEMS_4_FUNCTION_RES = 8765; + +pub fn items_4_function() -> u64 { + ITEMS_4_FUNCTION_RES +} + +pub trait Items4Trait { + fn items_4_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw new file mode 100644 index 00000000000..92293307319 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_3.sw @@ -0,0 +1,6 @@ +library; + +pub enum Items4_Variants2 { + M: bool, + N: bool, +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw new file mode 100644 index 00000000000..2f9d86748af --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/items_4_4.sw @@ -0,0 +1,6 @@ +library; + +pub enum Items4_Variants2 { + M: u64, + N: u64, +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw new file mode 100644 index 00000000000..642395e6bf1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_1.sw @@ -0,0 +1,22 @@ +library; + +pub use ::items_1::*; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 654; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw new file mode 100644 index 00000000000..44b21ced5ff --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_2.sw @@ -0,0 +1,9 @@ +library; + +pub use ::items_2_1::*; + +pub use ::items_2_2::Items2_Struct; +pub use ::items_2_2::Items2_Enum; +pub use ::items_2_2::ITEMS_2_FUNCTION_RES; +pub use ::items_2_2::items_2_function; +pub use ::items_2_2::Items2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw new file mode 100644 index 00000000000..04f9a81605f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_3.sw @@ -0,0 +1,28 @@ +library; + +pub use ::items_3_1::*; +pub use ::items_3_1::Items3_Variants::*; + +pub struct Items3_Struct { + pub c: u64, +} + +pub enum Items3_Enum { + E: u64, + F: u64, +} + +pub enum Items3_Variants { + G: u64, + H: u64, +} + +pub const ITEMS_3_FUNCTION_RES = 4321; + +pub fn items_3_function() -> u64 { + ITEMS_3_FUNCTION_RES +} + +pub trait Items3Trait { + fn items_3_trait_function(self, x: T) -> u64; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw new file mode 100644 index 00000000000..fa17194cde9 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/lib_4.sw @@ -0,0 +1,17 @@ +library; + +pub use ::items_4_1::*; +pub use ::items_4_1::Items4_Variants::*; + +pub use ::items_4_2::Items4_Struct; +pub use ::items_4_2::Items4_Enum; +pub use ::items_4_2::Items4_Variants; +pub use ::items_4_2::Items4_Variants::K; +pub use ::items_4_2::Items4_Variants::L; +pub use ::items_4_2::ITEMS_4_FUNCTION_RES; +pub use ::items_4_2::items_4_function; +pub use ::items_4_2::Items4Trait; + +pub use ::items_4_3::Items4_Variants2::*; +pub use ::items_4_4::Items4_Variants2::M; +pub use ::items_4_4::Items4_Variants2::N; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/main.sw new file mode 100755 index 00000000000..a2961173628 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/main.sw @@ -0,0 +1,20 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2_1; +mod items_2_2; +mod lib_2; // Item reexports of items_2_1 and items_2_2 +mod items_3_1; +mod lib_3; // Item reexports of items_3_1 and items_3_2 +mod items_4_1; +mod items_4_2; +mod items_4_3; +mod items_4_4; +mod lib_4; // Item reexports of items_4_1 and items_4_2 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/tests.sw new file mode 100644 index 00000000000..24e8370818e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/src/tests.sw @@ -0,0 +1,262 @@ +library; + +// Reexported items from items_1.sw. All reexports shadowed by local definitions in lib_1.sw. +use ::lib_1::*; + // Reexported items from items_2_1.sw and items_2_2.sw. All reexports from items_2_1.sw are + // shadowed by items imported from items_2_2.sw +use ::lib_2::*; +// Reexported items from items_3_1.sw and items_3_2.sw. All reexports shadowed by local definitions in lib_3.sw. +use ::lib_3::Items3_Struct; +use ::lib_3::Items3_Enum; +use ::lib_3::Items3_Variants; +use ::lib_3::Items3_Variants::G; +use ::lib_3::Items3_Variants::H; +use ::lib_3::ITEMS_3_FUNCTION_RES; +use ::lib_3::items_3_function; +use ::lib_3::Items3Trait; +// Reexported items from items_4_1.sw and items_4_2.sw. All reexports from items_4_1.sw are +// shadowed by items imported from items_4_2.sw +use ::lib_4::Items4_Struct; +use ::lib_4::Items4_Enum; +use ::lib_4::Items4_Variants; +use ::lib_4::Items4_Variants::K; +use ::lib_4::Items4_Variants::L; +use ::lib_4::ITEMS_4_FUNCTION_RES; +use ::lib_4::items_4_function; +use ::lib_4::Items4Trait; +// Items4_Variants2 defined in items_4_4.sw, variants reexported by lib_4.sw +use ::items_4_4::Items4_Variants2; +use ::lib_4::M; +use ::lib_4::N; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + self.Z + } + else { + 0 + } + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::C(val) => val, + Items2_Enum::D(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + 0 + } + else { + self.Z + } + } +} + + +// lib_3 tests + +fn project_items_3_struct(input: Items3_Struct) -> u64 { + input.c +} + +fn project_items_3_enum(input: Items3_Enum) -> u64 { + match input { + Items3_Enum::E(val) => val, + Items3_Enum::F(val) => val + 1000, + } +} + +fn project_items_3_variants(input: Items3_Variants) -> u64 { + match input { + Items3_Variants::G(val) => val, + Items3_Variants::H(val) => val + 1000, + } +} + +fn call_items_3_function() -> u64 { + items_3_function() +} + +impl Items3Trait for TestStruct1 { + fn items_3_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + self.Z + } + else { + 0 + } + } +} + +// lib_4 tests + +fn project_items_4_struct(input: Items4_Struct) -> u64 { + input.d +} + +fn project_items_4_enum(input: Items4_Enum) -> u64 { + match input { + Items4_Enum::I(val) => val, + Items4_Enum::J(val) => val + 1000, + } +} + +fn project_items_4_variants(input: Items4_Variants) -> u64 { + match input { + K(val) => val, + L(val) => val + 1000, + } +} + +fn call_items_4_function() -> u64 { + items_4_function() +} + +impl Items4Trait for TestStruct1 { + fn items_4_trait_function(self, x: TestStruct2) -> u64 { + if x.W { + 0 + } + else { + self.Z + } + } +} + +fn project_items_4_variants2(input: Items4_Variants2) -> u64 { + match input { + M(val) => val, + N(val) => val + 1000, + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res == 64); + + + let items_2_struct = Items2_Struct { b: 879 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 879); + + let items_2_enum = Items2_Enum::C(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res == 128); + + + let items_3_struct = Items3_Struct { c: 123 }; + let items_3_struct_res = project_items_3_struct(items_3_struct); + assert(items_3_struct_res == 123); + + let items_3_enum = Items3_Enum::E(432); + let items_3_enum_res = project_items_3_enum(items_3_enum); + assert(items_3_enum_res == 432); + + let items_3_variants = G(432); + let items_3_variants_res = project_items_3_variants(items_3_variants); + assert(items_3_variants_res == 432); + + let items_3_function_res = call_items_3_function(); + assert(items_3_function_res == ITEMS_3_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_3_trait_teststruct_1_res = teststruct_1.items_3_trait_function(teststruct_2); + assert(items_3_trait_teststruct_1_res == 64); + + + let items_4_struct = Items4_Struct { d: 879 }; + let items_4_struct_res = project_items_4_struct(items_4_struct); + assert(items_4_struct_res == 879); + + let items_4_enum = Items4_Enum::I(446); + let items_4_enum_res = project_items_4_enum(items_4_enum); + assert(items_4_enum_res == 446); + + let items_4_variants = K(446); + let items_4_variants_res = project_items_4_variants(items_4_variants); + assert(items_4_variants_res == 446); + + let items_4_function_res = call_items_4_function(); + assert(items_4_function_res == ITEMS_4_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 148 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_4_trait_teststruct_1_res = teststruct_1.items_4_trait_function(teststruct_2); + assert(items_4_trait_teststruct_1_res == 148); + + let items_4_variants2 = M(446); + let items_4_variants2_res = project_items_4_variants2(items_4_variants2); + assert(items_4_variants2_res == 446); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/test.toml new file mode 100755 index 00000000000..755870c91ef --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/shadowing_in_reexporting_module/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 19 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.lock new file mode 100755 index 00000000000..12796c9cfa0 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-01E3D9B036D3B866" + +[[package]] +name = "simple_glob_import" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-01E3D9B036D3B866" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.toml new file mode 100755 index 00000000000..e9e0963dbff --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_glob_import" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_2.sw new file mode 100755 index 00000000000..654a63ac267 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_1.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_2.sw new file mode 100644 index 00000000000..8689296a943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_2::*; + +pub use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/main.sw new file mode 100755 index 00000000000..57262307323 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/tests.sw new file mode 100644 index 00000000000..fe487e264c3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/src/tests.sw @@ -0,0 +1,126 @@ +library; + +use ::lib_1::*; // Reexported items from items_1.sw. All reexports are item imports +use ::lib_2::*; // Reexported items from items_2.sw. All reexports are glob imports + +use ::items_1::Items1_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.n +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::N(val) => val, + Items2_Enum::M(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + O(val) => val, + P(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { n: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::N(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = O(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/test.toml new file mode 100755 index 00000000000..0b73866a32b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_glob_import/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 1 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.lock new file mode 100755 index 00000000000..3153bd921ae --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-628D42C449EC89D5" + +[[package]] +name = "simple_item_import" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-628D42C449EC89D5" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.toml new file mode 100755 index 00000000000..37dd2996343 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_item_import" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_2.sw new file mode 100755 index 00000000000..654a63ac267 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_1.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_2.sw new file mode 100644 index 00000000000..8689296a943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_2::*; + +pub use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/main.sw new file mode 100755 index 00000000000..0b3777176d7 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_2 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/tests.sw new file mode 100644 index 00000000000..7a90a767dc2 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/src/tests.sw @@ -0,0 +1,142 @@ +library; + + // Reexported items from items_1.sw. All reexports are item imports +use ::lib_1::Items1_Struct; +use ::lib_1::Items1_Enum; +use ::lib_1::X; +use ::lib_1::Y; +use ::lib_1::ITEMS_1_FUNCTION_RES; +use ::lib_1::items_1_function; +use ::lib_1::Items1Trait; + +// Reexported items from items_2.sw. All reexports are glob imports +use ::lib_2::Items2_Struct; +use ::lib_2::Items2_Enum; +use ::lib_2::Items2_Variants; +use ::lib_2::O; +use ::lib_2::P; +use ::lib_2::ITEMS_2_FUNCTION_RES; +use ::lib_2::items_2_function; +use ::lib_2::Items2Trait; + +use ::items_1::Items1_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.n +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::N(val) => val, + Items2_Enum::M(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + O(val) => val, + P(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { n: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::N(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = O(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/test.toml new file mode 100755 index 00000000000..0b73866a32b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_item_import/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 1 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.lock new file mode 100755 index 00000000000..a7cf53ac834 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-F3FE5D74B284BFAB" + +[[package]] +name = "simple_path_access" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-F3FE5D74B284BFAB" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.toml new file mode 100755 index 00000000000..dbc40b43ba1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "simple_path_access" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_2.sw new file mode 100755 index 00000000000..250723123de --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub n: u64, +} + +pub enum Items2_Enum { + N: u64, + M: u64, +} + +pub enum Items2_Variants { + O: u64, + P: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_1.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_2.sw new file mode 100644 index 00000000000..8689296a943 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/lib_2.sw @@ -0,0 +1,5 @@ +library; + +pub use ::items_2::*; + +pub use ::items_2::Items2_Variants::*; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/main.sw new file mode 100755 index 00000000000..57262307323 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/main.sw @@ -0,0 +1,12 @@ +script; + +mod items_1; +mod lib_1; // Item reexports of items_1 +mod items_2; +mod lib_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/tests.sw new file mode 100644 index 00000000000..b627b80a247 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/src/tests.sw @@ -0,0 +1,97 @@ +library; + +// Disabled +// This test is supposed to test that `pub use` makes items available when accessed using a path, +// e.g., `::lib_1::X`, but the path resolution is broken, so the test doesn't test what it's +// supposed to test. + +use ::items_1::Items1_Variants; + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +impl ::lib_1::Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +impl ::lib_2::Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + +pub fn run_all_tests() -> u64 { + // lib_1 tests + let items_1_struct = ::lib_1::Items1_Struct { a: 123 }; + assert(items_1_struct.a == 123); + + let items_1_enum = ::lib_1::Items1_Enum::A(432); + let items_1_enum_res = match items_1_enum { + ::items_1::Items1_Enum::A(val) => val, + ::items_1::Items1_Enum::B(val) => val + 1000, + }; + assert(items_1_enum_res == 432); + + // TODO: Should this be allowed? ::lib_1::X refers to ::items_1::Items1_Variants::X. + let items_1_variants = ::lib_1::X(680); + let items_1_variants_res = match items_1_variants { + ::items_1::Items1_Variants::X(val) => val, + ::items_1::Items1_Variants::Y(val) => val + 1000, + }; + assert(items_1_variants_res == 680); + + let items_1_function_res = ::lib_1::items_1_function(); + let items_1_function_oracle = ::lib_1::ITEMS_1_FUNCTION_RES; + assert(items_1_function_res == items_1_function_oracle); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + // lib_2 tests + + let items_2_struct = ::lib_2::Items2_Struct { n: 789 }; + assert(items_2_struct.n == 789); + + let items_2_enum = ::lib_2::Items2_Enum::N(246); + let items_2_enum_res = match items_2_enum { + ::items_2::Items2_Enum::N(val) => val, + ::items_2::Items2_Enum::M(val) => val + 1000, + }; + assert(items_2_enum_res == 246); + + let items_2_variants = ::lib_2::O(468); + let items_2_variants_res = match items_2_variants { + ::items_2::Items2_Variants::O(val) => val, + ::items_2::Items2_Variants::P(val) => val + 1000, + }; + assert(items_2_variants_res == 468); + + let items_2_function_res = ::lib_2::call_items_2_function(); + let items_2_function_oracle = ::lib_2::ITEMS_2_FUNCTION_RES; + assert(items_2_function_res == items_2_function_oracle); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : false }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/test.toml new file mode 100755 index 00000000000..f5c00c330c8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/simple_path_access/test.toml @@ -0,0 +1,5 @@ +category = "disabled" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 0 \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.lock new file mode 100755 index 00000000000..70547186e1d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-3D27300F0A8AC1DF" + +[[package]] +name = "std" +source = "path+from-root-3D27300F0A8AC1DF" +dependencies = ["core"] + +[[package]] +name = "visibility" +source = "member" +dependencies = ["std"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.toml new file mode 100755 index 00000000000..e690d8f1785 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "visibility" +entry = "main.sw" +implicit-std = false + +[dependencies] +std = { path = "../../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle.json new file mode 100755 index 00000000000..2aa8f17eb3b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle_new_encoding.json new file mode 100755 index 00000000000..068da3305ab --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/json_abi_oracle_new_encoding.json @@ -0,0 +1,26 @@ +{ + "configurables": [], + "encoding": "1", + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "u64", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_1.sw new file mode 100644 index 00000000000..45f1e280573 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_1.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items1_Struct { + pub a: u64, +} + +pub enum Items1_Enum { + A: u64, + B: u64, +} + +pub enum Items1_Variants { + X: u64, + Y: u64, +} + +pub const ITEMS_1_FUNCTION_RES = 456; + +pub fn items_1_function() -> u64 { + ITEMS_1_FUNCTION_RES +} + +pub trait Items1Trait { + fn items_1_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_2.sw new file mode 100755 index 00000000000..1fa9465b0ec --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/items_2.sw @@ -0,0 +1,25 @@ +library; + +pub struct Items2_Struct { + pub b: u64, +} + +pub enum Items2_Enum { + C: u64, + D: u64, +} + +pub enum Items2_Variants { + Z: u64, + W: u64, +} + +pub const ITEMS_2_FUNCTION_RES = 987; + +pub fn items_2_function() -> u64 { + ITEMS_2_FUNCTION_RES +} + +pub trait Items2Trait { + fn items_2_trait_function(self, x: T) -> bool; +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_1.sw new file mode 100644 index 00000000000..37a603bf191 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_1.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_1::Items1_Struct; + +pub use ::items_1::Items1_Enum; + +pub use ::items_1::Items1_Variants::X; +pub use ::items_1::Items1_Variants::Y; + +pub use ::items_1::ITEMS_1_FUNCTION_RES; + +pub use ::items_1::items_1_function; + +pub use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_2.sw new file mode 100644 index 00000000000..27a37d85825 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_1_2.sw @@ -0,0 +1,14 @@ +library; + +use ::items_1::Items1_Struct; + +use ::items_1::Items1_Enum; + +use ::items_1::Items1_Variants::X; +use ::items_1::Items1_Variants::Y; + +use ::items_1::ITEMS_1_FUNCTION_RES; + +use ::items_1::items_1_function; + +use ::items_1::Items1Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_1.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_1.sw new file mode 100644 index 00000000000..b8b09eb5f35 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_1.sw @@ -0,0 +1,14 @@ +library; + +use ::items_2::Items2_Struct; + +use ::items_2::Items2_Enum; + +use ::items_2::Items2_Variants::Z; +use ::items_2::Items2_Variants::W; + +use ::items_2::ITEMS_2_FUNCTION_RES; + +use ::items_2::items_2_function; + +use ::items_2::Items2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_2.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_2.sw new file mode 100644 index 00000000000..825df78f630 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/lib_2_2.sw @@ -0,0 +1,14 @@ +library; + +pub use ::items_2::Items2_Struct; + +pub use ::items_2::Items2_Enum; + +pub use ::items_2::Items2_Variants::Z; +pub use ::items_2::Items2_Variants::W; + +pub use ::items_2::ITEMS_2_FUNCTION_RES; + +pub use ::items_2::items_2_function; + +pub use ::items_2::Items2Trait; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/main.sw new file mode 100755 index 00000000000..078a2114541 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/main.sw @@ -0,0 +1,14 @@ +script; + +mod items_1; +mod lib_1_1; // Item reexports of items_1 +mod lib_1_2; // Item imports without reexport of items_1 +mod items_2; +mod lib_2_1; // Item imports without reexport of items_1 +mod lib_2_2; // Item reexports of items_1 + +mod tests; // All tests + +fn main() -> u64 { + tests::run_all_tests() +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/tests.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/tests.sw new file mode 100644 index 00000000000..d03441d6016 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/src/tests.sw @@ -0,0 +1,128 @@ +library; + +use ::lib_1_1::*; // Reexported items from items_1.sw. +use ::lib_1_2::*; // Imported but not reexported items from items_1.sw. +use ::lib_2_1::*; // Imported but not reexported items from items_2.sw. +use ::lib_2_2::*; // Reexported items from items_2.sw. + +use ::items_1::Items1_Variants; +use ::items_2::Items2_Variants; + + +// Helper types + +struct TestStruct1 { + Z: u64, +} + +struct TestStruct2 { + W: bool, +} + + +// lib_1 tests + +fn project_items_1_struct(input: Items1_Struct) -> u64 { + input.a +} + +fn project_items_1_enum(input: Items1_Enum) -> u64 { + match input { + Items1_Enum::A(val) => val, + Items1_Enum::B(val) => val + 1000, + } +} + +fn project_items_1_variants(input: Items1_Variants) -> u64 { + match input { + X(val) => val, + Y(val) => val + 1000, + } +} + +fn call_items_1_function() -> u64 { + items_1_function() +} + +impl Items1Trait for TestStruct1 { + fn items_1_trait_function(self, x: TestStruct2) -> bool { + self.Z == 64 && x.W + } +} + + +// lib_2 tests + +fn project_items_2_struct(input: Items2_Struct) -> u64 { + input.b +} + +fn project_items_2_enum(input: Items2_Enum) -> u64 { + match input { + Items2_Enum::C(val) => val, + Items2_Enum::D(val) => val + 1000, + } +} + +fn project_items_2_variants(input: Items2_Variants) -> u64 { + match input { + Z(val) => val, + W(val) => val + 1000, + } +} + +fn call_items_2_function() -> u64 { + items_2_function() +} + +impl Items2Trait for TestStruct1 { + fn items_2_trait_function(self, x: TestStruct2) -> bool { + self.Z == 128 && x.W + } +} + + +pub fn run_all_tests() -> u64 { + let items_1_struct = Items1_Struct { a: 123 }; + let items_1_struct_res = project_items_1_struct(items_1_struct); + assert(items_1_struct_res == 123); + + let items_1_enum = Items1_Enum::A(432); + let items_1_enum_res = project_items_1_enum(items_1_enum); + assert(items_1_enum_res == 432); + + let items_1_variants = X(680); + let items_1_variants_res = project_items_1_variants(items_1_variants); + assert(items_1_variants_res == 680); + + let items_1_function_res = call_items_1_function(); + assert(items_1_function_res == ITEMS_1_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 64 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_1_trait_teststruct_1_res = teststruct_1.items_1_trait_function(teststruct_2); + assert(items_1_trait_teststruct_1_res); + + + let items_2_struct = Items2_Struct { b: 789 }; + let items_2_struct_res = project_items_2_struct(items_2_struct); + assert(items_2_struct_res == 789); + + let items_2_enum = Items2_Enum::C(246); + let items_2_enum_res = project_items_2_enum(items_2_enum); + assert(items_2_enum_res == 246); + + let items_2_variants = Z(468); + let items_2_variants_res = project_items_2_variants(items_2_variants); + assert(items_2_variants_res == 468); + + let items_2_function_res = call_items_2_function(); + assert(items_2_function_res == ITEMS_2_FUNCTION_RES); + + let teststruct_1 = TestStruct1 { Z : 128 }; + let teststruct_2 = TestStruct2 { W : true }; + let items_2_trait_teststruct_1_res = teststruct_1.items_2_trait_function(teststruct_2); + assert(items_2_trait_teststruct_1_res); + + 42 +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/test.toml new file mode 100755 index 00000000000..5341fe8486c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/reexport/visibility/test.toml @@ -0,0 +1,5 @@ +category = "run" +expected_result = { action = "return", value = 42 } +expected_result_new_encoding = { action = "return_data", value = "000000000000002A" } +validate_abi = true +expected_warnings = 0 \ No newline at end of file