From 406bc0367b73b8a3f0b26bb94da48b2726c7493e Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 19 Sep 2024 11:40:49 +0200 Subject: [PATCH] fix: Added missing type check when return statement as no returned value --- src/Codegen.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Codegen.zig b/src/Codegen.zig index ac15d669..6742a37d 100644 --- a/src/Codegen.zig +++ b/src/Codegen.zig @@ -3427,6 +3427,17 @@ fn generateReturn(self: *Self, node: Ast.Node.Index, breaks: ?*Breaks) Error!?*o _ = try self.generateNode(value, breaks); } else { + if (self.current.?.function.?.type_def.resolved_type.?.Function.return_type.def_type != .Void) { + self.reporter.reportTypeCheck( + .return_type, + self.ast.tokens.get(locations[self.current.?.function_node]), + self.current.?.function.?.type_def.resolved_type.?.Function.return_type, + self.ast.tokens.get(locations[node]), + self.gc.type_registry.void_type, + "Return value", + ); + } + try self.emitOpCode(locations[node], .OP_VOID); }