Skip to content

Commit

Permalink
fix(compiler): reserved words are not blocked (#3179)
Browse files Browse the repository at this point in the history
Fixes #3110

This is list is pretty naive, I think we should eventually do some mangling/cleanup of the JS we emit to avoid so many reserved values. Since I believe there's more work to do, I didn't touch the spec yet (See #1964).

This change will at least prevent strange runtime errors due to using reserved words. Added a special case for "constructor" as a method name, since it's not technically reserved elsewhere.

Misc:
- Changed the add_error in the parser to have a version that doesn't return anything. Sorry that this caused a bit of a noisy diff but I was so tired of that dumb `let _ = ...` thing

## Checklist

- [x] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/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 [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
  • Loading branch information
MarkMcCulloh authored Jun 30, 2023
1 parent e532784 commit f808f84
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 62 deletions.
3 changes: 3 additions & 0 deletions examples/tests/invalid/class.w
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,7 @@ inflight class Jet extends Plane{
super();
// ^^^^^^^^ Expected 1 positional argument(s) but got 0
}
constructor() {
//^^^^^^^^^^^ To declare a initializer, use "init"
}
}
3 changes: 3 additions & 0 deletions examples/tests/invalid/unknown_symbol.w
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ class A extends B {

unknown = 1;
//^ Unknown symbol

let let = 2;
//^^^ Reserved word
Loading

0 comments on commit f808f84

Please sign in to comment.