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

Mostly irrelevant, but possibly interesting variable declaration/assignment bug with let #13919

Closed
DanielSmedegaardBuus opened this issue Jun 26, 2017 · 2 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. repl Issues and PRs related to the REPL subsystem.

Comments

@DanielSmedegaardBuus
Copy link

DanielSmedegaardBuus commented Jun 26, 2017

  • Version: v8.1.0 (Homebrewed)
  • Platform: Darwin air.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64 i386 MacBookAir5,2 Darwin
  • Subsystem:

Obviously, this has no impact on production code, as any script execution would die after the first error, but I find it interesting that (console) node goes into this strange state where a declared variable is broken an cannot be "fixed".

This example is just to demonstrate the issue, copy/pasted from a node console:

> let a
undefined
> a = 1
1
> let b = c
ReferenceError: c is not defined
    at repl:1:9
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:278:10)
    at REPLServer.Interface._line (readline.js:625:8)
> b = 'c'
ReferenceError: b is not defined
    at repl:1:3
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:278:10)
    at REPLServer.Interface._line (readline.js:625:8)
> var b = c
SyntaxError: Identifier 'b' has already been declared

> b = 1
ReferenceError: b is not defined
    at repl:1:3
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:278:10)
    at REPLServer.Interface._line (readline.js:625:8)
>
@DanielSmedegaardBuus DanielSmedegaardBuus changed the title Mostly irrelevant, but possibly interesting variable declaration/assignment bug Mostly irrelevant, but possibly interesting variable declaration/assignment bug with let Jun 26, 2017
@vsemozhetbyt vsemozhetbyt added the repl Issues and PRs related to the REPL subsystem. label Jun 26, 2017
@dnalborczyk
Copy link
Contributor

Interesting. Though Chrome (59) behaves the same way. If anything, it's a v8 bug.

@bnoordhuis
Copy link
Member

See #8309 and the issues linked therein, the tl;dr is that the variable (per spec) stays in the TDZ. I'll close this as a duplicate but if anyone has ideas for a workaround, please chime in; see also the comment about the Firefox console in the linked issue.

@bnoordhuis bnoordhuis added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Jun 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants