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 {
var a = 3;
return a;
a = 2;
return a + 23;
}
fn f2() i32 {

View File

@ -339,10 +339,17 @@ pub const TypeSolver = struct {
}
},
else => {
std.debug.warn("TODO resolve expr {}\n", ast.ExprType(expr.*));
unreachable;
.Assign => |assign| {
var var_type = ctx.current_scope.?.env.get(
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
//var typ = self.findCurrent(assign.name);
@panic("TODO finish Assign emitting");
var assign_expr = try self.emitExpr(builder, assign.value);
// TODO rm null