| Summary: | [validation] The local variable is never read | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [WebTools] JSDT | Reporter: | Victor Homyakov <vkhomyackov> | ||||
| Component: | General | Assignee: | Project Inbox <jsdt.javascript-inbox> | ||||
| Status: | NEW --- | QA Contact: | Chris Jaun <cmjaun> | ||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | alex-pub.eclipse, pwampeeters | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Created attachment 207611 [details]
Minimal testcase to demonstrate bug
I think the bug comes about when the function is assigned to the global object. See the line:
GLOBAL_OBJ.foo = foo;
When it is present the variable 'read' will be incorrectly marked as never having been accessed, but commenting out the assignment above makes the warning
disappear.
In your example variable "read" is actually never read :) - there is no invocation of bar(), so IMHO warning is absolutely correct, although there may be also some indication of dead code e.g. "bar() is never invoked directly".
On the other side, when I rewrite my example as
(function() {
var pasteEventName = (Prototype.Browser.IE ? 'paste' : 'input'), storageKey = "mask_data";
function setMask(element) {
(function(element) {
var input = element;
if (!input.readAttribute("readonly")) {
input.observe("mask:unmask", function() {
input.store(storageKey, undefined).stopObserving(pasteEventName);
});
}
})(element);
return element;
}
setMask.storageKey = storageKey;
window.setMask = setMask;
})();
there is assignment to global variable, setMask() is publicly accessible, and "pasteEventName" is definitely read when invoking setMask(). Commenting line
window.setMask = setMask;
has no effect, but commenting/uncommenting line
setMask.storageKey = storageKey;
toggles warning. Note also incorrect highlighting of "storageKey" - 1st and last appearances are highlighted separately from 2nd and 3rd.
Another example:
(function() {
var moveCaretTimer = -1;
function setMask() {
(function() {
function focusEvent() {
var moveCaret = function() {
// empty
};
clearTimeout(moveCaretTimer);
moveCaretTimer = setTimeout(moveCaret, 0);
}
})();
}
setMask.storageKey = storageKey;
})();
moveCaretTimer is marked as never read, its occurrences not highlighted.
Bug still present in Eclipse Java EE IDE for Web Developers. Version: Juno Release Build id: 20120322-1740 Still present in Kepler JavaScript Development Tools Version: 1.5.0.v201301022000-7H7DFhZFC7sReqSz-frflXk Build id: 20120820000423 Still present in Luna. JavaScript Development Tools 1.6.0.v201405071612-7G7FFyXFBBoPc8Pvc8c0wn |
Overview: The local variable used in closure is marked as never read. Steps to Reproduce: Create JavaScript file (function() { var pasteEventName = (Prototype.Browser.IE ? 'paste' : 'input'), storageKey = "mask_data"; function setMask(element) { (function(element) { var input = element; if (!input.readAttribute("readonly")) { input.observe("mask:unmask", function() { input.store(storageKey, undefined).stopObserving(pasteEventName); }); } })(element); return element; } setMask.storageKey = storageKey; })(); Actual Results: Warning "The local variable pasteEventName is never read". Expected Results: No warning. Build Date & Platform: Eclipse J2EE Indigo 20110615-0604, JSDT 1.3.0.v201103031824