parser: fix unary operators causing stack overflow
This commit is contained in:
parent
65a9e58a9a
commit
3d47c0cca8
2 changed files with 8 additions and 4 deletions
|
@ -36,11 +36,14 @@ fn func_refer_param(b: i32) i32 {
|
|||
}
|
||||
|
||||
fn multwo(num: i32, double_flag: bool) i32 {
|
||||
if (!double_flag) {
|
||||
var value = false;
|
||||
return value;
|
||||
}
|
||||
|
||||
if (double_flag) {
|
||||
var truthy = true;
|
||||
return num * 2;
|
||||
} else {
|
||||
var falsey = false;
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1033,8 +1033,9 @@ pub const Parser = struct {
|
|||
|
||||
fn parseUnary(self: *@This()) anyerror!*Expr {
|
||||
if (self.compareAnyOf(&[_]TokenType{ .Bang, .Minus })) {
|
||||
var op = self.previous();
|
||||
var right = try self.parseUnary();
|
||||
var op = self.peek();
|
||||
_ = try self.nextToken();
|
||||
var right = try self.parseCall();
|
||||
|
||||
return try self.mkUnary(try toUnaryOperator(op), right);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue