analysis: add analysis of Assign expressions

This commit is contained in:
Luna 2019-09-28 22:48:59 -03:00
parent 2fea745df4
commit 5d8efd657f
3 changed files with 14 additions and 4 deletions

View file

@ -1,6 +1,7 @@
fn f() i32 { fn f() i32 {
var a = 3; var a = 3;
return a; a = 2;
return a + 23;
} }
fn f2() i32 { fn f2() i32 {

View file

@ -339,10 +339,17 @@ pub const TypeSolver = struct {
} }
}, },
else => { .Assign => |assign| {
std.debug.warn("TODO resolve expr {}\n", ast.ExprType(expr.*)); var var_type = ctx.current_scope.?.env.get(
unreachable; assign.name.lexeme,
).?.value;
var value_type = try self.resolveExprType(ctx, assign.value);
try self.expectSymUnTypeEqual(var_type, value_type);
return var_type;
}, },
.Set => @panic("TODO analysis of Set exprs"),
} }
} }

View file

@ -220,6 +220,8 @@ pub const Codegen = struct {
// we will also need to repeat the step for the type resolver // we will also need to repeat the step for the type resolver
//var typ = self.findCurrent(assign.name); //var typ = self.findCurrent(assign.name);
@panic("TODO finish Assign emitting");
var assign_expr = try self.emitExpr(builder, assign.value); var assign_expr = try self.emitExpr(builder, assign.value);
// TODO rm null // TODO rm null