Skip to content

Commit 6c42b5c

Browse files
committed
Feature(compiler): IfStatementCodeGenerator - Support terminator in else branch
1 parent 41a5023 commit 6c42b5c

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/backend/llvm/code-generation/if-statement.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export class IfStatementCodeGenerator implements NodeGenerateInterface<ts.IfStat
2828
builder.setInsertionPoint(negativeBlock);
2929
passNode(node.elseStatement, ctx, builder);
3030

31-
builder.createBr(next);
31+
if (!negativeBlock.getTerminator()) {
32+
builder.createBr(next);
33+
}
3234
} else {
3335
emitCondition(
3436
node.expression,

tests/snapshots/general/branch.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{
3+
function compareWithReturnInElse(left: number, right: number): string {
4+
console_log("compareWithReturnInElse");
5+
console_log(left);
6+
console_log(right);
7+
8+
if (left == right) {
9+
10+
} else {
11+
return "false";
12+
}
13+
14+
return "true";
15+
}
16+
17+
compareWithReturnInElse(1, 5);
18+
compareWithReturnInElse(5, 1);
19+
}

0 commit comments

Comments
 (0)