mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-26 12:49:21 +00:00
Added proper error when returning value from void function. Closes #400
This commit is contained in:
parent
ab10f2184d
commit
3dcec77fb7
@ -1678,6 +1678,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
KickCParser.CommaExprContext exprCtx = ctx.commaExpr();
|
||||
RValue rValue;
|
||||
if(exprCtx != null) {
|
||||
if(SymbolType.VOID.equals(procedure.getReturnType())) {
|
||||
throw new CompileError("Error! Return value from void function "+procedure.getFullName(), new StatementSource(ctx));
|
||||
}
|
||||
PrePostModifierHandler.addPreModifiers(this, exprCtx, new StatementSource(ctx));
|
||||
rValue = (RValue) this.visit(exprCtx);
|
||||
Variable returnVar = procedure.getLocalVariable("return");
|
||||
|
@ -3845,6 +3845,11 @@ public class TestPrograms {
|
||||
assertError("noreturn.c", "Method must end with a return statement", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnFromVoid() throws IOException, URISyntaxException {
|
||||
assertError("returnfromvoid.c", "Error! Return value from void function");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcedureNotFound() throws IOException, URISyntaxException {
|
||||
assertError("procedurenotfound.c", "Called procedure not found");
|
||||
|
9
src/test/kc/returnfromvoid.c
Normal file
9
src/test/kc/returnfromvoid.c
Normal file
@ -0,0 +1,9 @@
|
||||
// Return a value from a void function
|
||||
|
||||
void main() {
|
||||
print();
|
||||
}
|
||||
|
||||
void print() {
|
||||
return 2;
|
||||
}
|
Loading…
Reference in New Issue
Block a user