Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private modules can only be used in the entry file #5765

Closed
bitzoic opened this issue Mar 25, 2024 · 1 comment
Closed

Private modules can only be used in the entry file #5765

bitzoic opened this issue Mar 25, 2024 · 1 comment
Assignees
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@bitzoic
Copy link
Member

bitzoic commented Mar 25, 2024

When creating a folder structure for libraries, we have the following example:

my_project/
├── src/
│   ├── main.sw      # entry file
│   ├── other.sw     # Our library
│   └── other/
│       └── lib.sw   # Private module for other.sw
└── Forc.toml

Our library is defined in other.sw, however we have some helper functions in other/lib.sw we would like to keep private. This currently results in the following error:

Screenshot 2024-03-25 at 2 06 08 PM

With the following project structure this does not occur:

my_project
├── src
│   ├── main.sw      # entry file
│   └── other.sw     # Private module
└── Forc.toml

Example main.sw:

library;

pub mod other; // This is a public library

Example other.sw:

library;

mod lib; // Not a public library

use lib::PrivateStruct; // Error occurs here

// Public function
pub fn foo() {
    let my_struct = PrivateStruct { val: 0 };
}

Example other/lib.sw:

library;

pub struct PrivateStruct {
    pub val: u64,
}
@bitzoic bitzoic added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged labels Mar 25, 2024
bitzoic added a commit to FuelLabs/sway-libs that referenced this issue Mar 29, 2024
## Type of change

<!--Delete points that do not apply-->

- Improvement (refactoring, restructuring repository, cleaning tech
debt, ...)

## Changes

The following changes have been made:

- All imports have changed from multiple imports to a single imports
using the following:
```sway
libraries = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.4.0" }
```
From there your desired library may be imported:
```sway
use libraries::ownership::only_owner;
```

- Many of the primary functions have been moved out of the library's
folder. The documentation for this will be moved into a book in a follow
up PR.
- There are a number of private modules that are now exposed until
FuelLabs/sway#5765 is resolved.

## Notes

- This should get `forc doc` to produce a single document containing all
libraries rather than multiple documents for each library.

## Related Issues

<!--Delete everything after the "#" symbol and replace it with a number.
No spaces between hash and number-->

Closes #141
@jjcnn
Copy link
Contributor

jjcnn commented Jan 21, 2025

I can't reproduce this behavior. My guess is that the issue has been solved by one of these two commits:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

No branches or pull requests

2 participants