parser: fix unary operators causing stack overflow

This commit is contained in:
Luna 2019-09-28 17:52:30 -03:00
parent 65a9e58a9a
commit 3d47c0cca8
2 changed files with 8 additions and 4 deletions

View file

@ -36,11 +36,14 @@ fn func_refer_param(b: i32) i32 {
} }
fn multwo(num: i32, double_flag: bool) i32 { fn multwo(num: i32, double_flag: bool) i32 {
if (!double_flag) {
var value = false;
return value;
}
if (double_flag) { if (double_flag) {
var truthy = true;
return num * 2; return num * 2;
} else { } else {
var falsey = false;
return num; return num;
} }
} }

View file

@ -1033,8 +1033,9 @@ pub const Parser = struct {
fn parseUnary(self: *@This()) anyerror!*Expr { fn parseUnary(self: *@This()) anyerror!*Expr {
if (self.compareAnyOf(&[_]TokenType{ .Bang, .Minus })) { if (self.compareAnyOf(&[_]TokenType{ .Bang, .Minus })) {
var op = self.previous(); var op = self.peek();
var right = try self.parseUnary(); _ = try self.nextToken();
var right = try self.parseCall();
return try self.mkUnary(try toUnaryOperator(op), right); return try self.mkUnary(try toUnaryOperator(op), right);
} }