Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 358026

Summary: Selecting a local variable occurrence in an anonymous function can cause variable occurrences with the same name in other functions to be highlighted
Product: [WebTools] JSDT Reporter: John Field <jfield>
Component: GeneralAssignee: Chris Jaun <cmjaun>
Status: ASSIGNED --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cmjaun, hyukmin0530.kwon, jaeheung.kim, kgurals, Michael_Rennie, thatnitind
Version: unspecified   
Target Milestone: Future   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Bugfix 358026
none
testcases for this bug
none
Bugfix 358026 none

Description John Field CLA 2011-09-18 10:58:38 EDT
Build Identifier: 20110615-0604

Selecting an occurrence of a local variable or parameter of an anonymous function can cause occurrences of variables or parameters with the same name in _other_ anonymous functions to be highlighted as well.

It appears that the functions need to declare variables in similar orders and/or have similar signatures in order for the problem to manifest itself.

This may be related to bug 351473.



Reproducible: Always

Steps to Reproduce:
1. Create the following functions:

var foo = function() { var it = 17; return it; };
var bar = function() { var it = 18; return it; };
var baz = function(it) { return it; };
var boo = function(it) { return it; };

2. Click on an occurrence of 'it' in function 'foo'.  Occurrences of 'it' in 'bar' (but not 'baz' or 'boo' are also highlighted.  Clicking on an occurrence of 'it' in 'baz' will highlight the occurrence in 'boo' but those in 'foo' or 'bar.
Comment 1 Wooyoung Cho CLA 2012-04-26 22:49:46 EDT
Created attachment 214651 [details]
Bugfix 358026

VariableBinding.isEqualTo() method cannot distinguish two variable bindings with same <modifier,name,type,id(declaration order in a method)> declared in two different function expressions with same <selector,returnType,declaringClass,parameters>.
This is the cause of this bug.
I think that current implementation has no actual way to check equality of two method bindings of this case. MethodBindings don't have something like unique id or link to declaration.
This patch resolves binding equality problem for LocalVariableBindings by comparing declaration ASTNodes of local variable bindings so that at least the equality of local variable bindings are correctly checked.
Comment 2 Wooyoung Cho CLA 2012-04-26 22:51:36 EDT
Created attachment 214652 [details]
testcases for this bug

This zip file includes testcases for Mark Occurrences similar to Content Assist.
Comment 3 Nitin Dahyabhai CLA 2012-04-27 13:07:08 EDT
(In reply to comment #1)
> Created attachment 214651 [details]

Unless you actually want to cede the copyright to IBM, you probably want to correct it to that of your employer (the key thing is to keep it EPL).
Comment 4 Wooyoung Cho CLA 2012-04-30 01:34:48 EDT
Created attachment 214785 [details]
Bugfix 358026

The company name in license boilerplate text is replaced as Nitin said. 
Thanks.
Comment 5 Chris Jaun CLA 2013-08-01 13:48:43 EDT
The problem in question seems to have been fixed indirectly by another patch because this is currently working in WTP 3.5.1 without applying the patch.

Though, I think it would be good to pull in the test cases contributed by Wooyoung.