| Summary: | Array initialization with length specified is not expected | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Huang Ji Yong <hjiyong> |
| Component: | EDT | Assignee: | 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: | |||
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.
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. Re-routing to Validation to disallow the following:
a int[] = new int[1]{5};
Validation has been added to prevent this confusing syntax. The following files were changed: DefaultBinder IProblemRequestor EGLValidationResource.properties Verified in build 0.8.0.v201201172212 |
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].