From b76c91ec056ccc5f61cddcec8d026a9f541de0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Sat, 12 Dec 2020 13:52:22 +0100 Subject: [PATCH] parser: silent mode fixes (#7286) --- vlib/v/checker/checker.v | 4 ++++ vlib/v/parser/if_match.v | 2 +- vlib/v/parser/parse_type.v | 11 +++++++++++ vlib/v/parser/parser.v | 8 ++------ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 856781a98c..63e468ceec 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3565,6 +3565,10 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, type_sym table.TypeSymbol } c.expected_type = node.cond_type expr_type := c.expr(expr) + if expr_type.idx() == 0 { + // parser failed, stop checking + return + } if cond_type_sym.kind == .interface_ { // TODO // This generates a memory issue with TCC diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 08c381ed20..722beb5c02 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -173,7 +173,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { p.next() } else if p.tok.kind == .name && !(p.tok.lit == 'C' && p.peek_tok.kind == .dot) && (p.tok.lit in table.builtin_type_names || p.tok.lit[0].is_capital() || - (p.peek_tok.kind == .dot && p.peek_tok2.lit[0].is_capital())) { + (p.peek_tok.kind == .dot && p.peek_tok2.lit.len > 0 && p.peek_tok2.lit[0].is_capital())) { mut types := []table.Type{} for { // Sum type match diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index aef65da27f..2c887c3558 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -48,6 +48,10 @@ pub fn (mut p Parser) parse_map_type() table.Type { } p.check(.lsbr) key_type := p.parse_type() + if key_type.idx() == 0 { + // error is reported in parse_type + return 0 + } // key_type_sym := p.get_type_symbol(key_type) // if key_type_sym.kind != .string { if key_type.idx() != table.string_type_idx { @@ -56,6 +60,10 @@ pub fn (mut p Parser) parse_map_type() table.Type { } p.check(.rsbr) value_type := p.parse_type() + if value_type.idx() == 0 { + // error is reported in parse_type + return 0 + } idx := p.table.find_or_register_map(key_type, value_type) return table.new_type(idx) } @@ -78,6 +86,9 @@ pub fn (mut p Parser) parse_multi_return_type() table.Type { mut mr_types := []table.Type{} for p.tok.kind != .eof { mr_type := p.parse_type() + if mr_type.idx() == 0 { + break + } mr_types << mr_type if p.tok.kind == .comma { p.next() diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 632771ae99..fe213bba41 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1021,14 +1021,10 @@ pub fn (mut p Parser) parse_ident(language table.Language) ast.Ident { } scope: p.scope } - } else { - p.error('unexpected token `$p.tok.lit`') - return ast.Ident{ - scope: 0 - } } + p.error('unexpected token `$p.tok.lit`') return ast.Ident{ - scope: 0 + scope: p.scope } }