Skip to content

Commit 9a077e4

Browse files
committed
[Heavy] Fix nested ifs in tail pos
1 parent fe7fdcc commit 9a077e4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

heavy/lib/OpGen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,11 @@ mlir::Value OpGen::createIf(SourceLocation Loc, Value Cond, Value Then,
877877
Builder.setInsertionPointToStart(Block);
878878
mlir::Value Result = Visit(Value);
879879
Block = Builder.getBlock();
880-
if (Block->empty() || !isa<ApplyOp>(Block->back()))
880+
if (Result) {
881+
assert(Block->empty() ||
882+
!Block->back().hasTrait<mlir::OpTrait::IsTerminator>());
881883
create<ContOp>(Loc, Result);
884+
}
882885
};
883886

884887
handleBranch(Then, ThenBlock);

heavy/test/Evaluate/if.scm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,19 @@
103103
(write
104104
(if (null? 42) 'return-baz))
105105
(newline)
106+
107+
; Should compile
108+
(define (maybe-literal-op* Arg)
109+
(define AttrVal
110+
(if (number? Arg)
111+
(write (number->string Arg))
112+
(if (symbol? Arg)
113+
(error "oof")
114+
(if (string? Arg)
115+
(error "woof")
116+
#f))))
117+
(if AttrVal
118+
'ok
119+
Arg))
120+
; CHECK-NEXT: "5"
121+
(maybe-literal-op* 5)

0 commit comments

Comments
 (0)