Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fc098b155 | ||
|
|
32ddb1132f | ||
|
|
174c999543 | ||
|
|
942b8ca488 |
No files matched your search
@@ -0,0 +1,12 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
public class Bug412 {
|
||||
public m(Integer i) {
|
||||
var r = 0;
|
||||
switch (i) {
|
||||
case 1: r = 10; break;
|
||||
default: r = 20;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
}
|
||||
@@ -405,14 +405,16 @@ public class StatementGenerator {
|
||||
|
||||
private SwitchBlock convert(Java17Parser.SwitchBlockStatementGroupContext stmt) {
|
||||
List<SwitchLabel> labels = new ArrayList<>();
|
||||
stmt.switchLabel().forEach((label) -> {
|
||||
var isDefault = false;
|
||||
for (var label : stmt.switchLabel()) {
|
||||
if (label instanceof SwitchLabelDefaultContext) isDefault = true;
|
||||
labels.add(convert(label));
|
||||
});
|
||||
}
|
||||
List<Statement> block = new ArrayList<>();
|
||||
stmt.blockStatement().stream().forEach((blockStmt) -> {
|
||||
block.addAll(convert(blockStmt));
|
||||
});
|
||||
return new SwitchBlock(labels, new Block(block, stmt.blockStatement(0).getStart()), false, stmt.getStart());
|
||||
return new SwitchBlock(labels, new Block(block, stmt.blockStatement(0).getStart()), isDefault,false, stmt.getStart());
|
||||
}
|
||||
|
||||
private SwitchLabel convert(SwitchLabelContext switchLabel) {
|
||||
|
||||
@@ -476,7 +476,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
.map(this::extractAllPatterns)
|
||||
.flatMap(List::stream).toList();
|
||||
case FormalParameter param -> List.of(new TypeVariants(param.getType(), converter.findAllVariants(param.getType())));
|
||||
default -> List.of();
|
||||
case null, default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1759,4 +1759,14 @@ public class TestComplete {
|
||||
assertEquals("one", name.invoke(instance, 1));
|
||||
assertEquals("many", name.invoke(instance, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug412() throws Exception {
|
||||
var classFiles = generateClassFiles(createClassLoader(), "Bug412.jav");
|
||||
var clazz = classFiles.get("Bug412");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
var m = clazz.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(10, m.invoke(instance, 1));
|
||||
assertEquals(20, m.invoke(instance, 2));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user