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

Compile error when classes in different modules have the same name #3640

Closed
Chriscbr opened this issue Jul 27, 2023 · 2 comments · Fixed by #3743
Closed

Compile error when classes in different modules have the same name #3640

Chriscbr opened this issue Jul 27, 2023 · 2 comments · Fixed by #3743
Assignees
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Jul 27, 2023

I tried this:

// main.w
bring "./foo.w" as foo;
bring "./bar.w" as bar;

assert(foo.Util.foo() == "foo");
assert(bar.Util.bar() == "bar");

// foo.w
class Util {
  static foo(): str {
    return "foo";
  }
}

// bar.w
class Util {
  static bar(): str {
    return "bar";
  }
}

This happened:

error: Cannot add two files with the same name: ./inflight.Util.js

I expected this:

It compiles

Is there a workaround?

Give the classes different names

Component

Compiler

Wing Version

0.24.47

Node.js Version

No response

Platform(s)

MacOS

Anything else?

The JSifier needs to emit inflight clients in a way so that classes with the same name still get different generated names. For example, the file stem could be used to distinguish the names like inflight.foo-Util.js and inflight.bar-Util.js, or an incrementing number could be used.

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 Jul 27, 2023
@Chriscbr
Copy link
Contributor Author

Chriscbr commented Aug 8, 2023

Looks like this issue also pops up with inflight closures. For example:

// file1.w
bring "./file2.w" as file2;

class Foo {
  init() {
    let x = inflight () => {};
  }
}

// file2.w
class B {
  init() {
    let x = inflight () => {};
  }
}

throws the error:

error: Cannot add two files with the same name: ./inflight.$Closure1.js

@Chriscbr Chriscbr self-assigned this Aug 8, 2023
@mergify mergify bot closed this as completed in #3743 Aug 10, 2023
mergify bot pushed a commit that referenced this issue Aug 10, 2023
Fixes #3640

This change affects a lot of files, so I've implemented the changes and updated examples in the first commit, and all snapshot updates in the second commit.

## 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)
- [ ] 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.24.92.

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.

2 participants