This commit is contained in:
nub31
2025-07-03 19:16:28 +02:00
parent 585317e428
commit fee4951a96
5 changed files with 41 additions and 30 deletions

View File

@@ -188,13 +188,29 @@ public static class Binder
private static BoundVariableDeclarationNode BindVariableDeclaration(VariableDeclarationNode statement)
{
_variables[statement.Name] = statement.Type;
NubType? type = null;
if (statement.ExplicitType.HasValue)
{
type = statement.ExplicitType.Value;
}
var assignment = Optional<BoundExpressionNode>.Empty();
if (statement.Assignment.HasValue)
{
assignment = BindExpression(statement.Assignment.Value);
var boundValue = BindExpression(statement.Assignment.Value, type);
assignment = boundValue;
type = boundValue.Type;
}
return new BoundVariableDeclarationNode(statement.Tokens, statement.Name, statement.Type, assignment);
if (type == null)
{
throw new NotImplementedException("Diagnostics not implemented");
}
_variables[statement.Name] = type;
return new BoundVariableDeclarationNode(statement.Tokens, statement.Name, statement.ExplicitType, assignment, type);
}
private static BoundWhileNode BindWhile(WhileNode statement)
@@ -254,8 +270,7 @@ public static class Binder
private static BoundArrayInitializerNode BindArrayInitializer(ArrayInitializerNode expression)
{
return new BoundArrayInitializerNode(expression.Tokens, new NubArrayType(expression.ElementType), BindExpression(expression.Capacity, NubPrimitiveType.U64),
expression.ElementType);
return new BoundArrayInitializerNode(expression.Tokens, new NubArrayType(expression.ElementType), BindExpression(expression.Capacity, NubPrimitiveType.U64), expression.ElementType);
}
private static BoundBinaryExpressionNode BindBinaryExpression(BinaryExpressionNode expression)