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

Disallow interfaces definitions except at the top-level #5542

Closed
Chriscbr opened this issue Jan 25, 2024 · 4 comments · Fixed by #7036
Closed

Disallow interfaces definitions except at the top-level #5542

Chriscbr opened this issue Jan 25, 2024 · 4 comments · Fixed by #7036
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Jan 25, 2024

Use Case

For the same reason we disallow structs except at the top-level of a file (see #5135). Interfaces only define contracts (they don't contain any source code) so there aren't strong use cases to support defining interfaces within if branches or as a result of code execution etc.

bring math;

if math.random() < 0.5 {
  interface Foo {
    foo(): str;
  }
} else {
  interface Foo {
    foo(): num;
  }
}

Proposed Solution

No response

Implementation Notes

No response

Component

Compiler

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.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Slack.
@Chriscbr Chriscbr added ✨ enhancement New feature or request 🛠️ compiler Compiler needs-discussion Further discussion is needed prior to impl labels Jan 25, 2024
@Chriscbr
Copy link
Contributor Author

@yoav-steinberg @eladb any objections?

@staycoolcall911
Copy link
Contributor

@Chriscbr, please see #5507 - we may have to support interface definitions inside classes through jsii.

@staycoolcall911 staycoolcall911 added the 📐 language-design Language architecture label Jan 29, 2024
@Chriscbr
Copy link
Contributor Author

Got it, after reading Mark's comment I see how they're related - good callout.

(2 cents) Even if we support interface definitions existing inside classes in our type system (for backwards compatibility with existing JSII libraries, like the issue above shows), I think it might still be reasonable to prevent the creation of new interfaces in this way within Wing code.

@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
🛠️ compiler Compiler ✨ enhancement New feature or request 📐 language-design Language architecture
Projects
Status: Done
3 participants