Skip to content

Commit

Permalink
Feature(compiler): IfStatementCodeGenerator - Support terminator in e…
Browse files Browse the repository at this point in the history
…lse branch
  • Loading branch information
ovr committed Jan 15, 2019
1 parent 41a5023 commit 6c42b5c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/backend/llvm/code-generation/if-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export class IfStatementCodeGenerator implements NodeGenerateInterface<ts.IfStat
builder.setInsertionPoint(negativeBlock);
passNode(node.elseStatement, ctx, builder);

builder.createBr(next);
if (!negativeBlock.getTerminator()) {
builder.createBr(next);
}
} else {
emitCondition(
node.expression,
Expand Down
19 changes: 19 additions & 0 deletions tests/snapshots/general/branch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

{
function compareWithReturnInElse(left: number, right: number): string {
console_log("compareWithReturnInElse");
console_log(left);
console_log(right);

if (left == right) {

} else {
return "false";
}

return "true";
}

compareWithReturnInElse(1, 5);
compareWithReturnInElse(5, 1);
}

0 comments on commit 6c42b5c

Please sign in to comment.