Closed Bug 411279 Opened 17 years ago Closed 17 years ago

let in switch yield "not directly within block"

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla1.9beta3

People

(Reporter: nmaier, Assigned: brendan)

References

()

Details

(Keywords: regression, testcase)

Attachments

(2 files)

Attached file simple testcase (deleted) —
checkin from bug #410981 broke 'let' declarations inside of a switch block. See testcase for details. Testcase is OK for pre-checkin builds incl. for Gecko 1.8/Fx2, but fails for post-checkin builds. (Noticed because DownThemAll! trunk was hit by this; see URL)
Nils, my best guess is Brendan will mark this invalid. Is there any reason to use let in this case rather than var?
This predicts more breakage, in my experience. The "let is the new var" slogan is in trouble if you can't just use let x = 42; first thing in a case's statementlist (sure, it's funky if that hoists to top of switch body-block, but that's the least evil interpretation, and it's what JS1.7 did). We may have to carry this as an extension to JS2/ES4, but it could be important usability "signal", not noise. /be
Assignee: general → brendan
Flags: blocking1.9?
Priority: -- → P1
Target Milestone: --- → mozilla1.9 M11
Bob, I'm concerned about two things: 1. We may have to continue to support something JS1.7 supported. This is often good business on the web, standards that go against it notwithstanding. 2. The emergent standard may want to include support for let in unbraced switch case statementlist, because that's overwhelmingly likely to be coded by authors who are told "let is the new var", and it's a natural thing to do. /be
(In reply to comment #2) > This predicts more breakage, in my experience. The "let is the new var" slogan > is in trouble if you can't just use let x = 42; first thing in a case's > statementlist (sure, it's funky if that hoists to top of switch body-block, but > that's the least evil interpretation, and it's what JS1.7 did). huh? What do you mean by this? > We may have to carry this as an extension to JS2/ES4, but it could be important > usability "signal", not noise. > Naive thoughts: I can't see any reason why it should be valid to have 'var' there but no 'let'; the scope is pretty clear to me (the switch *block*). I didn't read the (proposed) standards, but if they don't allow this then IMO they should be "fixed".
Priority: P1 → --
Target Milestone: mozilla1.9 M11 → ---
Nils: what "this" do you mean? The paragraph you cited pretty much agrees with what you wrote in your "Naive thoughts:" paragraph. I did call it "funky" for x in switch (y) { // three thousand lines of cases and statement lists... case 3000: let x = 42; ... ... } to be hoisted all the way up to the switch's body block, but again: we shipped that in JS1.7 (Firefox 2) and that's what DownThemAll depends on. So this bug should be fixed for now, since it is late in the Firefox 3 game to be breaking more addons and we have evidence of breakage. True, we could hang tough and say "change your code", but that's a good way to piss off developers. If it were earlier in the Firefox 3 cycle, maybe. Now is a bad time, IMHO, because if we are wrong in calculating risks to-do with addon and XUL app authors defecting because we "broke the platform", we have no recourse. If we can remove this per ES4 (JS2) as proposed later, we should try, and that avoids the risks. Call me a coward, but I'd rather defer risk taking till ES4 is more settled and we have time to reach all the platform consumers who may depend on let in switch case statementlist working as in JS1.7. So I'm fixing this for beta 3. /be
Status: NEW → ASSIGNED
Priority: -- → P1
Target Milestone: --- → mozilla1.9 M11
See bug 410900 comment 4 where myk agrees with a proposed better style even for js1.7, to wit: switch (y) { // three thousand lines of cases and statement lists... case 3000: { let x = 42; ... } ... } One could use a let block too: switch (y) { // three thousand lines of cases and statement lists... case 3000: let (x = 42) { ... } ... } Layout squished to eliminate newlines, but you get the idea. Still, I don't want to try to contact (that's hard enough) and force (worse, in the extreme case) everyone who depended on unbraced let in switch case stmtlist to change in a hurry. /be
Depends on: 408957
No longer depends on: 410981
Attached patch patch (deleted) — Splinter Review
With this patch: js> function f(x){switch(x){case 1:print(1, y); break; case 2: let y=42; print(2, y); break; default:print('default', y)}} js> f function f(x) { switch (x) { case 1: print(1, y); break; case 2: let y = 42; print(2, y); break; default: print("default", y); } } js> f(1) 1 undefined js> f(2) 2 42 js> f(3) default undefined /be
Attachment #295992 - Flags: review?(mrbkap)
Attachment #295992 - Flags: review?(mrbkap) → review+
Blocks: 408957
No longer depends on: 408957
Fixed: js/src/jsemit.h 3.89 js/src/jsparse.c 3.323 /be
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
/cvsroot/mozilla/js/tests/js1_7/block/regress-411279.js initial revision: 1.1
Flags: in-testsuite+
Flags: in-litmus-
Just to make sure, it's correct for this to give a "redeclaration of variable <var>" error: switch (x) { case 1: let variable; break; case 2: let variable; break; }
(In reply to comment #10) > switch (x) { > case 1: let variable; break; > case 2: let variable; break; > } Oh, I just realized this wasn't an issue with var because you can redeclare "var variable" as many times as you want.
v
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: