Fixed bug with return statement and updates tests
This commit is contained in:
parent
58b5d07dd6
commit
d9570d4393
|
@ -2323,6 +2323,10 @@ proc deferStmt(self: Compiler, node: DeferStmt) =
|
||||||
|
|
||||||
proc returnStmt(self: Compiler, node: ReturnStmt) =
|
proc returnStmt(self: Compiler, node: ReturnStmt) =
|
||||||
## Compiles return statements
|
## Compiles return statements
|
||||||
|
if self.currentFunction.valueType.returnType.isNil() and not node.value.isNil():
|
||||||
|
self.error("cannot return a value from a void function", node.value)
|
||||||
|
elif not self.currentFunction.valueType.returnType.isNil() and node.value.isNil():
|
||||||
|
self.error("bare return statement is only allowed in void functions", node)
|
||||||
if not node.value.isNil():
|
if not node.value.isNil():
|
||||||
self.expression(node.value)
|
self.expression(node.value)
|
||||||
self.emitByte(OpCode.SetResult, node.token.line)
|
self.emitByte(OpCode.SetResult, node.token.line)
|
||||||
|
|
|
@ -798,7 +798,7 @@ proc getRelativeBoundaries*(self: ASTNode): tuple[start, stop: int] =
|
||||||
if self.pragmas.len() > 0:
|
if self.pragmas.len() > 0:
|
||||||
stop = getRelativeBoundaries(self.pragmas[^1]).stop
|
stop = getRelativeBoundaries(self.pragmas[^1]).stop
|
||||||
result = (start, stop)
|
result = (start, stop)
|
||||||
of breakStmt:
|
of breakStmt, returnStmt, continueStmt:
|
||||||
result = self.token.relPos
|
result = self.token.relPos
|
||||||
of importStmt:
|
of importStmt:
|
||||||
result = (self.token.relPos.start, getRelativeBoundaries(ImportStmt(self).moduleName).stop)
|
result = (self.token.relPos.start, getRelativeBoundaries(ImportStmt(self).moduleName).stop)
|
||||||
|
|
|
@ -7,6 +7,6 @@ fn identity(x: int32): int32 {
|
||||||
|
|
||||||
# No call is necessary for the compiler to detect the error:
|
# No call is necessary for the compiler to detect the error:
|
||||||
# generics are type checked at declaration time!
|
# generics are type checked at declaration time!
|
||||||
fn nope[T: int32 | int16](x: T) {
|
fn nope[T: int32 | int16](x: T): T {
|
||||||
return identity(x);
|
return identity(x);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue