fix: 空函数不生成代码的问题

This commit is contained in:
zhangxun 2025-07-10 15:00:41 +08:00
parent d9b3593e9b
commit 9f6a1edccb

View File

@ -2,6 +2,7 @@ package org.jcnc.snow.compiler.parser.function;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.ReturnNode;
import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.base.TopLevelParser;
import org.jcnc.snow.compiler.parser.ast.FunctionNode;
@ -72,6 +73,9 @@ public class FunctionParser implements TopLevelParser {
Map<String, SectionDefinition> sections = getSectionDefinitions(parameters, returnType, body);
FlexibleSectionParser.parse(ctx, ts, sections);
if (body.isEmpty() && returnType[0].equals("void")) {
body.add(new ReturnNode(null, new NodeContext(line, column, file)));
}
parseFunctionFooter(ts);