Bug 23048 - DOM - lazy initialization of empty loop bodies causes binding resolution to fail
Summary: DOM - lazy initialization of empty loop bodies causes binding resolution to fail
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-30 15:54 EDT by mark_dixon CLA
Modified: 2002-09-19 11:08 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mark_dixon CLA 2002-08-30 15:54:10 EDT
Using build I200208270833

Running this code

IWorkspace ws = testcasesPlugin.getWorkspace();
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProjects()[0];
IJavaProject jp = JavaCore.create(project);
		
CompilationUnit cu = AST.parseCompilationUnit(
   "public class Class {void theMethod() {for (int i = 0; i < 5; ++i); theMethod
();}}".toCharArray(),
   "Class", jp);
cu.accept(new ASTVisitor() {
   public boolean visit(SimpleName node) {
      IBinding binding = node.resolveBinding();
      if (null == binding) {
         System.out.println("Null binding for SimpleName " + node.getIdentifier
());
      }
      return true;
   }
});

produces the output
Null binding for SimpleName i
Null binding for SimpleName theMethod

The null binding for 'i' is, I assume, bug 11529.  The null binding for the 
invocation of theMethod is caused by the call to ForStatement.getBody() in 
ForStatement.accept0().  This calls ForStatement.setBody() because the for 
statement had an empty body.  The call to setBody changes the modification 
count on the AST which causes all further attempts at binding resolution to 
return null.  I think the lazy initialization has to go :-)  Similarly for 
other loops.

Thanks
Mark
Comment 1 Olivier Thomann CLA 2002-09-03 11:07:21 EDT
The body of the forStatement should be set during the conversion. I will
investigate.
Comment 2 Olivier Thomann CLA 2002-09-03 12:47:35 EDT
This is an issue related to the empty statement. I am looking into it. Other
statements are broken and I'd like to fix all of them at the same time.
Comment 3 Olivier Thomann CLA 2002-09-03 14:45:47 EDT
Fixed and released in 2.1 stream.
Comment 4 David Audel CLA 2002-09-19 04:49:05 EDT
Verified.
Comment 5 Olivier Thomann CLA 2002-09-19 11:08:23 EDT
Regression tests added (test0371, test0372)