Community
Participate
Working Groups
Following bug 104492, the position for byte[] bs in the enhanced for statement are bogus. public class X { public static void main(String[] args) { byte[] b1 = new byte[0]; byte[] b2 = new byte[0]; for (byte[] bs : new byte[][] { b1, b2 }) { } } }
The bug comes from the wrong position for the compiler's array type reference. In the case of the enhanced for statement, if the expression after the colon is an array initializer, the endPosition in the parser is not the end of the array type reference anymore. I might be able to fix this in the AST converter, but the positions would remain boggus for the compiler's node. So if we report errors against the type reference, the highlighting might be boggus.
This can be addressed with a grammar change. Changing the rules to consume EnhancedForStatementHeader to: EnhancedForStatementHeaderInit ::= 'for' '(' Type PushModifiers Identifier Dimsopt /.$putCase consumeEnhancedForStatementHeaderInit(false); $break ./ /:$readableName EnhancedForStatementHeaderInit:/ EnhancedForStatementHeaderInit ::= 'for' '(' Modifiers Type PushRealModifiers Identifier Dimsopt /.$putCase consumeEnhancedForStatementHeaderInit(true); $break ./ /:$readableName EnhancedForStatementHeaderInit:/ EnhancedForStatementHeader ::= EnhancedForStatementHeaderInit ':' Expression ')' /.$putCase consumeEnhancedForStatementHeader(); $break ./ /:$readableName EnhancedForStatementHeader:/ /:$compliance 1.5:/ Doing this when EnhancedForStatementHeaderInit is reduced, the this.endPosition has the right value.
Fixed and released in HEAD. Regression tests in org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test0199/0201.
Added new regression test in Regression tests in org.eclipse.jdt.core.tests.dom.ASTConverter15Test.test0202
Verified for 3.2 M3 using ASTView and build I20051025-0800+v_619