Add additional test case to cover "var"
This commit is contained in:
@ -2135,7 +2135,8 @@ E.g. `int[] x = new int[] { 1, 2, 3 };` can be written as `int[] x = { 1, 2, 3 }
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value><![CDATA[
|
||||
//VariableDeclarator
|
||||
//(LocalVariableDeclaration[@TypeInferred = false()] | FieldDeclaration)
|
||||
/VariableDeclarator
|
||||
[VariableDeclaratorId[@ArrayType = true()]]
|
||||
[VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ArrayDimsAndInits/ArrayInitializer]
|
||||
]]></value>
|
||||
|
@ -77,6 +77,19 @@ public class UseShortArrayExample {
|
||||
private int[] f2 = new int[] {1,2,3}, f3 = new int[] { 4,5,6 };
|
||||
|
||||
private int[] good = { 1,2,3 };
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>array initialization with var</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class UseShortArrayExample {
|
||||
public void foo() {
|
||||
var ar1 = new int[] { 1, 2 };
|
||||
//var ar2 = { 1, 2 }; // this is actually a compile-time error and is forbidden. See JLS 14.4.
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user