Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366495 - Array initialization with length specified is not expected
Summary: Array initialization with length specified is not expected
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-13 02:40 EST by Huang Ji Yong CLA
Modified: 2017-02-23 14:19 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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