fix regression in AST node iteration

the new iteration code caused an integer underflow for function
prototypes with no parameters. now fixed.
master
Andrew Kelley 2020-05-24 10:03:08 -04:00
parent 2ff3995a70
commit 1c0b7ddda8
1 changed files with 3 additions and 3 deletions

View File

@ -706,7 +706,6 @@ pub const Node = struct {
return null; return null;
} }
pub fn firstToken(self: *const VarDecl) TokenIndex { pub fn firstToken(self: *const VarDecl) TokenIndex {
if (self.visib_token) |visib_token| return visib_token; if (self.visib_token) |visib_token| return visib_token;
if (self.thread_local_token) |thread_local_token| return thread_local_token; if (self.thread_local_token) |thread_local_token| return thread_local_token;
@ -1049,7 +1048,9 @@ pub const Node = struct {
i -= 1; i -= 1;
} }
const params_len = switch (self.paramsConst()[self.params_len - 1].param_type) { const params_len: usize = if (self.params_len == 0)
0
else switch (self.paramsConst()[self.params_len - 1].param_type) {
.var_type, .type_expr => self.params_len, .var_type, .type_expr => self.params_len,
.var_args => self.params_len - 1, .var_args => self.params_len - 1,
}; };
@ -2660,7 +2661,6 @@ pub const Node = struct {
} }
}; };
pub fn iterate(self: *const Asm, index: usize) ?*Node { pub fn iterate(self: *const Asm, index: usize) ?*Node {
var i = index; var i = index;