Skip to content

Commit ed80ad0

Browse files
committed
Fixed issue #187 "Compilation of vars initialized in different if/else branches is failing".
1 parent 9c0fb03 commit ed80ad0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

janino/src/main/java/org/codehaus/janino/UnitCompiler.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,8 @@ interface ClassFileConsumer {
15891589
}
15901590

15911591
/**
1592-
* Called to check whether the given {@link Rvalue} compiles or not.
1592+
* Called to check whether the given {@link BlockStatement} compiles or not.
1593+
* Updates the stack map of the current inserter.
15931594
*
15941595
* @return Whether the block statement can complete normally
15951596
*/
@@ -1604,7 +1605,6 @@ interface ClassFileConsumer {
16041605

16051606
this.getCodeContext().removeCode(from, to);
16061607

1607-
this.codeContext.currentInserter().setStackMap(from.getStackMap());
16081608
return ccn;
16091609
}
16101610

@@ -2570,10 +2570,12 @@ private enum SwitchKind { INT, ENUM, STRING }
25702570
final CodeContext.Inserter ins = this.getCodeContext().newInserter();
25712571
StackMap smBeforeSeeingStatement = this.codeContext.currentInserter().getStackMap();
25722572
boolean ssccn = this.compile(seeingStatement);
2573+
Offset afterSeeingStatement = this.codeContext.newOffset();
25732574

25742575
// Fake-compile the blind statement.
25752576
this.codeContext.currentInserter().setStackMap(smBeforeSeeingStatement);
25762577
boolean bsccn = this.fakeCompile(blindStatement);
2578+
afterSeeingStatement.setStackMap(); // Merge stack maps after seeing and after blind statements.
25772579

25782580
if (ssccn) return true;
25792581
if (!bsccn) return false;
@@ -2611,7 +2613,6 @@ private enum SwitchKind { INT, ENUM, STRING }
26112613
boolean tsccn = this.compile(ts);
26122614
if (tsccn) {
26132615
this.gotO(is, end);
2614-
} else {
26152616
}
26162617

26172618
// Compile "else" statment.

0 commit comments

Comments
 (0)