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

Cannot bring using the same alias multiple times in a directory #4415

Closed
Chriscbr opened this issue Oct 4, 2023 · 3 comments · Fixed by #4591
Closed

Cannot bring using the same alias multiple times in a directory #4415

Chriscbr opened this issue Oct 4, 2023 · 3 comments · Fixed by #4591
Assignees
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler
Milestone

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Oct 4, 2023

I tried this:

// main.w
bring "./subdir" as subdir;

// subdir/foo.w
bring "./util.w" as util;

// subdir/bar.w
bring "./util.w" as util;

// subdir/util.w
class Util {}

This happened:

error: Symbol "util" has multiple definitions in "subdir"
  --> bring_subdir.test.w:1:1
  |
1 | bring "./subdir" as subdir;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Symbol "util" has multiple definitions in "subdir"

I expected this:

No error

Is there a workaround?

Rename one of the imports:

bring "./util.w" as util2;

Component

Compiler

Wing Version

0.34.14

Node.js Version

18.14.1

Platform(s)

MacOS

Anything else?

It should be possible to fix this with #4294 (adding technology to track a symbol's "access" inside symbol environments)

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@Chriscbr Chriscbr added 🐛 bug Something isn't working 🛠️ compiler Compiler labels Oct 4, 2023
@Chriscbr Chriscbr changed the title Symbol has multiple definitions Cannot import files under the same name multiple times within a directory Oct 4, 2023
@Chriscbr Chriscbr changed the title Cannot import files under the same name multiple times within a directory Cannot bring using the same alias multiple times in a directory Oct 4, 2023
@eladb
Copy link
Contributor

eladb commented Oct 4, 2023

Oouch

@Chriscbr Chriscbr mentioned this issue Oct 4, 2023
5 tasks
mergify bot pushed a commit that referenced this issue Oct 5, 2023
Introduces the `wing pack` command - a standard way to package libraries in Wing.

`wing pack` can be run in any Wing project directory that has a `package.json` in it. `wing pack` will validate your `package.json` produce a tarball that contains the libraries source files. For more documentation, see https://winglang.io/docs/libraries.

## Implementation

When you `bring "foo"`, the parser now performs some Node module resolution to look up the `foo` package and see if it's a JSII library or a Wing library based on its `package.json`. If `bring "foo"` refers to a Wing library, then it's equivalent to bringing that library's root directory, per #4210.

## Future related work
- #4415
- #4294
- #2171

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@eladb
Copy link
Contributor

eladb commented Oct 10, 2023

This is quite blocking when using built in modules. I can't bring util in two different files within the same module.

@staycoolcall911 staycoolcall911 added this to the KubeCon23 milestone Oct 10, 2023
@Chriscbr Chriscbr self-assigned this Oct 13, 2023
@mergify mergify bot closed this as completed in #4591 Oct 19, 2023
mergify bot pushed a commit that referenced this issue Oct 19, 2023
…nums (#4591)

Wing now supports declaring classes, structs, interfaces, and enums as public using the `pub` access modifier. The default access of all types is now private.

This PR also fixes a bug where you could not `bring` modules under the same alias in different files.

Closes #4294
Closes #4415
Closes #2763

BREAKING CHANGE: All types are private by default. To make a class, struct, or other declaration accessible to other files, prefix it with the `pub` access modifier.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [x] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.41.0.

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 Compiler
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants