...
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user