Bug 8832

Summary: Sanity check error (internal error) when unused variables inside initializers
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P1    
Version: 2.0   
Target Milestone: 2.0 M3   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Philipe Mulet CLA 2002-01-31 09:57:12 EST
Build 20020125

When compiling the following test case, the compiler reports an incorrect error
revealing an internal bug:

package p2;
public class X {
	int field = 0;
	{
		int i;
		int k;
	}
	X() {
		int j = 0;
		field = 1;
		if (field == 1) System.out.println("SUCCESS");
	}
	public static void main(String[] arguments) {
		new X();
	}
}

---
----------
1. ERROR in ...\p2\X.java (at line 3)
	public class X {
	             ^
SANITY CHECK: Invalid attribute for local variable k
----------
Comment 1 Philipe Mulet CLA 2002-01-31 10:00:58 EST
This only occurs when asking local variable attributes, and this is due to the 
fact that the variables <i> and <k> ids are colliding with <j> (ok since in 
different scopes). However, when exiting the block scope(exitUserScope) for the 
initializer, unused variables are not removed from the visible variables list.

Then later on in the constructor body (since initializers are inlined inside 
constructors), this interferes with normal visible variables debug attribute 
generation, since the unused ones have same indexes as legite ones.

Fixed by ensuring the visible variables are properly flushed (even if unused).
Comment 2 Philipe Mulet CLA 2002-08-20 18:49:15 EDT
Backporting it to 1.0 for jck1.3a compliance.