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

class field declaration and assignment is not respected #4474

Closed
eladcon opened this issue Oct 9, 2023 · 3 comments
Closed

class field declaration and assignment is not respected #4474

eladcon opened this issue Oct 9, 2023 · 3 comments
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@eladcon
Copy link
Collaborator

eladcon commented Oct 9, 2023

I tried this:

class C {
  s: str = "123";
  init() {
  }
}

This happened:

eladcohen@Elads-w-MacBook-Pro a2 % wing test main.w
error: Preflight field "s" is not initialized
  --> main.w:2:7
  |
2 |   pub s: str = "123";
  |       ^ Preflight field "s" is not initialized

I expected this:

i wont have to explicitly assign to s again in init (or at least a compiler error on the declaration line)

Is there a workaround?

No response

Component

Compiler

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Anything else?

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.
@eladcon eladcon added the 🐛 bug Something isn't working label Oct 9, 2023
@Chriscbr
Copy link
Contributor

I don't believe this syntax is supported yet (see #3121). Perhaps it should have produced a syntax error instead?

@Chriscbr Chriscbr added the 🛠️ compiler Compiler label Oct 10, 2023
@eladcon
Copy link
Collaborator Author

eladcon commented Oct 10, 2023

Wasn't aware of that issue, yeah i guess it should be an error

@staycoolcall911
Copy link
Contributor

I don't think we should keep an issue for adding an error message for this case, since #3121 is p1.
I think we can close this for now.

Semi-related: #3121 will be split to 3 issues for default values in structs, classes and function signatures.

@staycoolcall911 staycoolcall911 closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
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

No branches or pull requests

3 participants