winglang/wing
Auf GitHub ansehenReferenceError: Cannot access variable before initialization
Open
#2.266 geöffnet am 25. Apr. 2023
good first issue🐛 bug🛠️ compiler
Repository-Metriken
- Stars
- (5.385 Stars)
- PR-Merge-Metriken
- (Keine gemergten PRs in 30 T)
Beschreibung
I tried this
// wing code
log("");
let body = "hello";
log(body);
if true {
let body = "${body}world";
log(body);
}
log(body);
Instead, this happened
--------------------------------- STACK TRACE ---------------------------------
evalmachine.<anonymous>:12
const body = `${body}world`;
^
ReferenceError: Cannot access 'body' before initialization
at new $Root (evalmachine.<anonymous>:12:20)
at new $App (evalmachine.<anonymous>:22:7)
at evalmachine.<anonymous>:33:1
I expected this:
It should be a compile time error (surfaced by the language server during type checking). We need to implement a check validating that in any let-statement that declares a new variable X, X may not appear as a subexpression on its right hand side.
Is there a workaround?
Use a different variable name
Component
Compiler
Wing Version
0.13.25
Wing Console Version
No response
Node.js Version
18.14.1
Platform(s)
MacOS
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.