mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8210742: compound var declaration type is not uniform for all variables
Make implicit type for all variables in compound declaration as null for which type inference happens at later phase Reviewed-by: mcimadamore
This commit is contained in:
parent
73ad9c4a00
commit
e4f60a8489
2 changed files with 26 additions and 4 deletions
|
@ -1041,6 +1041,28 @@ public class JavacParserTest extends TestCase {
|
|||
assertEquals("the error message is not correct, actual: " + actualErrors, expectedErrors, actualErrors);
|
||||
}
|
||||
|
||||
@Test //JDK-821742
|
||||
void testCompDeclVarType() throws IOException {
|
||||
String code = "package test; public class Test {"
|
||||
+ "private void test() {"
|
||||
+ "var v1 = 10,v2 = 12;"
|
||||
+ "} private Test() {}}";
|
||||
|
||||
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
|
||||
null, null, Arrays.asList(new MyFileObject(code)));
|
||||
CompilationUnitTree cut = ct.parse().iterator().next();
|
||||
ct.enter();
|
||||
ct.analyze();
|
||||
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
|
||||
MethodTree method = (MethodTree) clazz.getMembers().get(0);
|
||||
VariableTree stmt1 = (VariableTree) method.getBody().getStatements().get(0);
|
||||
VariableTree stmt2 = (VariableTree) method.getBody().getStatements().get(1);
|
||||
Tree v1Type = stmt1.getType();
|
||||
Tree v2Type = stmt2.getType();
|
||||
assertEquals("Implicit type for v1 is not correct: ", Kind.PRIMITIVE_TYPE, v1Type.getKind());
|
||||
assertEquals("Implicit type for v2 is not correct: ", Kind.PRIMITIVE_TYPE, v2Type.getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCaseBodyStatements() throws IOException {
|
||||
String code = "class C {" +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue