From d0e2f2a05ebda5bab5c03d5b618575381d689393 Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Mon, 28 Jul 2025 20:50:33 -0700 Subject: [PATCH] fix a small bug with return values --- .../pizza/pork/compiler/IrStubOpEmitter.kt | 1 + examples/bad.pork | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt b/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt index 5601918..2664ba7 100644 --- a/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt +++ b/compiler/src/main/kotlin/gay/pizza/pork/compiler/IrStubOpEmitter.kt @@ -18,6 +18,7 @@ class IrStubOpEmitter(val irDefinition: IrDefinition, val code: CodeBuilder) : I fun final() { if (code.lastOp()?.op?.code != Opcode.Return) { + code.emit(Opcode.None) code.emit(Opcode.Return) } } diff --git a/examples/bad.pork b/examples/bad.pork index 966078c..5b9056a 100644 --- a/examples/bad.pork +++ b/examples/bad.pork @@ -1,5 +1,9 @@ func depth(i: int32) { + if i <= 0 { + return None + } println("Depth: ", i) + depth(i - 1) } export func main() { @@ -11,5 +15,19 @@ export func main() { true } - return println("uhm, bad") + if true { + + } else { + + } + + if false { + + } else { + + } + + depth(500) + + println("uhm, bad") }