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

pub or internal types can be declared inside local scopes #7035

Closed
Chriscbr opened this issue Aug 20, 2024 · 1 comment · Fixed by #7036
Closed

pub or internal types can be declared inside local scopes #7035

Chriscbr opened this issue Aug 20, 2024 · 1 comment · Fixed by #7036
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@Chriscbr
Copy link
Contributor

I tried this:

for i in 0..1 {
  pub class MyClass {}
  new MyClass();
}

This happened:

The code compiles

I expected this:

I expected an type checking error to be raised. There's no way for classes defined within inner scopes (within if statements, for loops, functions, or other classes) to be possibly consumed by other files, and it's possible to statically detect this based on where the class is defined in the code, so we should indicate to the user that their code is invalid.

The same logic should also apply for structs, enums, and interfaces as well.

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.82.7

Node.js Version

20.11.1

Platform(s)

No response

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 Aug 20, 2024
@Chriscbr Chriscbr changed the title pub or internal types should only be allowed at the top-level of a Wing file pub or internal types can be declared inside local scopes Aug 20, 2024
@mergify mergify bot closed this as completed in #7036 Aug 21, 2024
@mergify mergify bot closed this as completed in eca0508 Aug 21, 2024
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.83.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
Status: Done
2 participants