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

feat: var declarations #1180

Merged
merged 17 commits into from Jan 18, 2023
Merged

feat: var declarations #1180

merged 17 commits into from Jan 18, 2023

Conversation

Chriscbr
Copy link
Contributor

@Chriscbr Chriscbr commented Jan 17, 2023

This change introduces the var modifier, which indicates that a variable can be reassigned to. For example:

let var sum = 0;
for item in [1, 2, 3] {
  sum = sum + item;
}

Partially addresses #109 (only implements the modifier for variables, not for class/resource fields)

Also fixes a bug where expressions used in an interpolated string are not recognized as captures.

By submitting this pull request, I confirm that my contribution is made under the terms of the
Monada Contribution License
.

docs/04-reference/winglang-spec.md Outdated Show resolved Hide resolved
examples/tests/valid/vars.w Outdated Show resolved Hide resolved
@eladb
Copy link
Contributor

eladb commented Jan 17, 2023

The compiler doesn't yet check that let variables cannot be reassigned to, but this has not been an issue to date in preflight since it is translated into const in JavaScript code.

Do we have a tracking issue for this?

@Chriscbr
Copy link
Contributor Author

Not yet. Will create

Also I need to add a test that "var" symbols cannot be captured (right?)

@Chriscbr
Copy link
Contributor Author

Awaiting feedback from @yoav-steinberg

docs/04-reference/winglang-spec.md Show resolved Hide resolved
libs/wingc/src/capture.rs Show resolved Hide resolved
libs/wingc/src/type_check.rs Show resolved Hide resolved
docs/04-reference/winglang-spec.md Outdated Show resolved Hide resolved
docs/04-reference/winglang-spec.md Outdated Show resolved Hide resolved
docs/04-reference/winglang-spec.md Show resolved Hide resolved
examples/tests/invalid/capture_reassignable.w Outdated Show resolved Hide resolved
libs/tree-sitter-wing/test/corpus/statements.txt Outdated Show resolved Hide resolved
libs/tree-sitter-wing/test/corpus/statements.txt Outdated Show resolved Hide resolved
Signed-off-by: github-actions <github-actions@github.com>
@Chriscbr Chriscbr merged commit 1d50eea into main Jan 18, 2023
@Chriscbr Chriscbr deleted the rybickic/var branch January 18, 2023 12:31
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.4.106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants