Fixed error message when returning values from void functions

This commit is contained in:
Mattia Giambirtone 2022-07-10 15:10:01 +02:00
parent 70c839f5b8
commit 9cedc72f68
2 changed files with 2 additions and 2 deletions

View File

@ -27,7 +27,7 @@ when len(PEON_COMMIT_HASH) != 40:
const PEON_BRANCH* = "master"
when len(PEON_BRANCH) > 255:
{.fatal: "The git branch name's length must be less than or equal to 255 characters".}
const DEBUG_TRACE_VM* = true # Traces VM execution
const DEBUG_TRACE_VM* = false # Traces VM execution
const DEBUG_TRACE_GC* = false # Traces the garbage collector (TODO)
const DEBUG_TRACE_ALLOCATION* = false # Traces memory allocation/deallocation
const DEBUG_TRACE_COMPILER* = false # Traces the compiler

View File

@ -1464,7 +1464,7 @@ proc returnStmt(self: Compiler, node: ReturnStmt) =
self.error(&"call to undeclared function '{CallExpr(node.value).callee.token.lexeme}'")
self.error(&"expected return value of type '{self.typeToStr(expected)}', but expression has no type")
elif expected.isNil() and not actual.isNil():
self.error("empty return statement is only allowed in void functions")
self.error("void function cannot return any value")
elif not self.compareTypes(actual, expected):
self.error(&"expected return value of type '{self.typeToStr(expected)}', got '{self.typeToStr(actual)}' instead")
if not node.value.isNil():