parser: prevent a segfault, when compiling cmd/tools/vtest-vet.v in PR 6754

pull/6763/head
Delyan Angelov 2020-11-05 19:40:15 +02:00
parent 3f9b05a876
commit 953d102996
1 changed files with 4 additions and 3 deletions

View File

@ -390,9 +390,9 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
typ := table.new_type(reg_idx) typ := table.new_type(reg_idx)
mut ts := p.table.get_type_symbol(typ) mut ts := p.table.get_type_symbol(typ)
// if methods were declared before, it's an error, ignore them // if methods were declared before, it's an error, ignore them
ts.methods.clear() ts.methods = []table.Fn{cap:20}
// Parse methods // Parse methods
mut methods := []ast.FnDecl{} mut methods := []ast.FnDecl{cap:20}
for p.tok.kind != .rcbr && p.tok.kind != .eof { for p.tok.kind != .rcbr && p.tok.kind != .eof {
method_start_pos := p.tok.position() method_start_pos := p.tok.position()
line_nr := p.tok.line_nr line_nr := p.tok.line_nr
@ -425,7 +425,8 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl {
if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr { if p.tok.kind.is_start_of_type() && p.tok.line_nr == line_nr {
method.return_type = p.parse_type() method.return_type = p.parse_type()
} }
method.comments = p.eat_comments() mcomments := p.eat_comments()
method.comments = mcomments
methods << method methods << method
// println('register method $name') // println('register method $name')
return_type_sym := p.table.get_type_symbol(method.return_type) return_type_sym := p.table.get_type_symbol(method.return_type)