Community
Participate
Working Groups
Build Identifier: I20110613-1736 The key variable in a for-in loop is reported as "not initialized" (When the corresponding warning is enabled in the validation settings): function test() { var k, a; a = {}; for (k in a) {} } I think this is wrong. "k" does not need to be initialized, it will be initialized with the keys of the iterated object during the for-loop. Reproducible: Always
Created attachment 215039 [details] Patch to fix bug 351338 Flow analysis sees the "k" as a reference to "var k". Problem can be fixed simply enough by not traversing the SingleNameReference for "k" at all; it cannot possibly change flow information, and is included as "definitely assigned" later on anyway.
Created attachment 215209 [details] Patch to fix bug 351338 Improved (and reduced) patch
Chris, I have reviewed this patch and validated it resolves this problem. I recommend it to be included in 3.5.1. Could you officially complete this review?
The issue with this patch is it just shifts the problem. If it doesn't enter the analyseCode method, then the variable does not get flagged as "used", so now that error message incorrectly shows up instead. Will look to see if there is another solution. There is also some movement towards removing some of these types of error messages from JSDT going forward, so it could get cleaned up that way too.
*** Bug 391406 has been marked as a duplicate of this bug. ***