This commit is contained in:
nub31
2025-09-20 02:01:53 +02:00
parent f5a292312f
commit d4fabdd6c9
4 changed files with 19 additions and 11 deletions

View File

@@ -6,7 +6,9 @@ public abstract record TerminalStatementNode : StatementNode;
public record BlockNode(List<StatementNode> Statements) : StatementNode;
public record StatementExpressionNode(ExpressionNode Expression) : StatementNode;
public record StatementFuncCallNode(FuncCallNode FuncCall) : StatementNode;
public record StatementStructFuncCallNode(StructFuncCallNode StructFuncCall) : StatementNode;
public record ReturnNode(Optional<ExpressionNode> Value) : TerminalStatementNode;

View File

@@ -203,9 +203,16 @@ public sealed class TypeChecker
return new ReturnNode(value);
}
private StatementExpressionNode CheckStatementExpression(StatementExpressionSyntax statement)
private StatementNode CheckStatementExpression(StatementExpressionSyntax statement)
{
return new StatementExpressionNode(CheckExpression(statement.Expression));
var expression = CheckExpression(statement.Expression);
return expression switch
{
FuncCallNode funcCall => new StatementFuncCallNode(funcCall),
StructFuncCallNode structFuncCall => new StatementStructFuncCallNode(structFuncCall),
_ => throw new TypeCheckerException(Diagnostic.Error("Expressions statements can only be function calls").At(statement).Build())
};
}
private VariableDeclarationNode CheckVariableDeclaration(VariableDeclarationSyntax statement)