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

Bug 366495

Summary: Array initialization with length specified is not expected
Product: z_Archived Reporter: Huang Ji Yong <hjiyong>
Component: EDTAssignee: Project Inbox <edt.compiler-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: jeffdouglas, pharmon, svihovec
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Huang Ji Yong CLA 2011-12-13 02:40:12 EST
A test case:

package test;

// program
//
program b363897	
	a int[] = new int[1]{5};
	
	function main()
	    syslib.writeStdout(a[1]);
	end	
end

The output value is 0.
The a array is initialized to [0, 5] which is expected to [5].
Comment 1 Jeff Douglas CLA 2011-12-22 14:38:23 EST
I will have to check with Tim, but I believe this is working correctly and it is the testcase that might be faulty.

The new int[1] tells EDT to define a new array predefined with 1 element, which is defaulting to 0. The {5} then adds an additional element with a value of 5.

If you define it this way, then you will get what the testcase is looking for:

    a0 int[] = new int[]{5};

Until I talk with Tim, this will be on hold.
Comment 2 Brian Svihovec CLA 2012-01-06 16:04:10 EST
I agree with Jeff's statements in comment 1, and EDT is currently behaving correctly.  The following behavior occurs in Java:

int[] var1 = new int[]{5};  // Array of size 1, with index 0 == 5
int[] var2 = new int[1]{5}; // invalid - can't specify both size and initializer
int[] var3 = new int[1];    // Array of size 1, with index 0 == 0

I believe we should leave things as is, and open an enhancement for validation to disallow both a size and an initializer.
Comment 3 Brian Svihovec CLA 2012-01-09 16:23:15 EST
Re-routing to Validation to disallow the following:

 a int[] = new int[1]{5};
Comment 4 Paul Harmon CLA 2012-01-17 15:42:51 EST
Validation has been added to prevent this confusing syntax. The following files were changed:

DefaultBinder
IProblemRequestor
EGLValidationResource.properties
Comment 5 Huang Ji Yong CLA 2012-01-18 03:55:13 EST
Verified in build 0.8.0.v201201172212