- Handle `ReturnInstruction` with no expression

Test cases

- Added `simple_return_expressionless.t`
This commit is contained in:
Tristan B. Velloza Kildaire 2024-05-07 10:02:14 +02:00
parent 5f81ac41db
commit 301a6615ad
2 changed files with 18 additions and 4 deletions

View File

@ -392,10 +392,18 @@ public final class DCodeEmitter : CodeEmitter
Context context = returnInstruction.getContext();
assert(context);
/* Get the return expression instruction */
Value returnExpressionInstr = returnInstruction.getReturnExpInstr();
emmmmit = "return "~transform(returnExpressionInstr)~";";
/* If there is an expression returned */
if(returnInstruction.hasReturnExpInstr())
{
/* Get the return expression instruction */
Value returnExpressionInstr = returnInstruction.getReturnExpInstr();
emmmmit = "return "~transform(returnExpressionInstr)~";";
}
/* Expression-less return */
else
{
emmmmit = "return;";
}
}
/**
* If statements (IfStatementInstruction)

View File

@ -0,0 +1,6 @@
module simple_return_expressionless;
void func()
{
return;
}