Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 313825 - Erroneous local variable's problems reported at surrounding ParenthesizedExpression
Summary: Erroneous local variable's problems reported at surrounding ParenthesizedExpr...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5.2   Edit
Hardware: All All
: P3 normal with 1 vote (vote)
Target Milestone: 3.6.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-20 18:47 EDT by Chris West (Faux) CLA
Modified: 2010-08-26 03:07 EDT (History)
4 users (show)

See Also:
srikanth_sankaran: review+


Attachments
Proposed fix + regression test (3.14 KB, patch)
2010-05-25 12:49 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (3.14 KB, patch)
2010-05-26 12:07 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris West (Faux) CLA 2010-05-20 18:47:08 EDT
Build Identifier: M20100211-1343

If you have a parenthesized expression (ParenthesizedExpression) containing just a variable/field reference (SimpleName), and that local variable is in error (undeclared, possibly uninitialised, etc.), the problem is reported for the entire expression, instead of the expected name.

From a UI perspective, this shows as, in:

class Scratch { void foo(int q) {
 foo(
  (
//^ here
   a
  )
//^ to here
 );
}}

... the entire section between the indicated brackets being underlined in red, including the comment.


From an API consumer point of view, the IProblem#getStartPosition() does not refer to the same point as the SimpleName#getStartPosition() for that variable error.

Workaround for consumers:
private int getRealErrorReportPosition(final SimpleName sn) {
 ASTNode test = sn;
 while (test.getParent() instanceof ParenthesizedExpression)
  test = test.getParent();
 return test.getStartPosition();
}


Reproducible: Always

Steps to Reproduce:
1. Paste the above class into a Java editor.
2. Note that "a" is in error, but the red-underlining for the error situation extends from the (unnecessary) open bracket to the close bracket.
Comment 1 Markus Keller CLA 2010-05-21 09:18:42 EDT
Same in 3.6. Only seems to happen for ParenthesizedExpression. When I e.g. add a "-" in front of the "a", the error range becomes correct.
Comment 2 Olivier Thomann CLA 2010-05-25 12:49:42 EDT
Created attachment 169854 [details]
Proposed fix + regression test
Comment 3 Olivier Thomann CLA 2010-05-25 12:50:13 EDT
Too late for 3.6. Targeting 3.6.1 as the fix is trivial.
Comment 4 Olivier Thomann CLA 2010-05-26 12:07:21 EDT
Created attachment 170032 [details]
Proposed fix + regression test

Updated the patch to match fix for 306464 that belongs to the same file (ProblemReporter).
Comment 5 Olivier Thomann CLA 2010-06-17 12:14:37 EDT
Srikanth, please review.
Comment 6 Srikanth Sankaran CLA 2010-06-18 04:36:31 EDT
Patch looks good.
Comment 7 Olivier Thomann CLA 2010-06-18 12:22:42 EDT
Released in HEAD and 3.6.1
Comment 8 Satyam Kandula CLA 2010-06-21 01:57:19 EDT
(In reply to comment #7)
> Released in HEAD and 3.6.1
The code changes didn't go to HEAD -- the test was failing. I have released the code changes to HEAD.
Comment 9 Srikanth Sankaran CLA 2010-08-26 03:07:14 EDT
Verified for 3.6.1 RC2 using Build id: M20100825-0800