From: Rico Tzschichholz Date: Tue, 16 Jun 2020 12:55:04 +0000 (+0200) Subject: parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON X-Git-Tag: 0.49.1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fmerge-requests%2F128%2Fhead;p=thirdparty%2Fvala.git parser: Avoid mitigation for missing token if it follows DOT or DOUBLE_COLON Rolling back to a DOT/DOUBLE_COLON token will retrigger the attempt to parse an incomplete member access. Regression of 4368a4fa667148378dcdbd251a4ae4e00c9a8e5a Fixes https://gitlab.gnome.org/GNOME/vala/issues/987 --- diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 191bc75d5..3adc6e71a 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -104,10 +104,25 @@ public class Vala.Parser : CodeVisitor { assert (size <= BUFFER_SIZE); } + inline void safe_prev () { + switch (previous ()) { + case TokenType.DOT: + case TokenType.DOUBLE_COLON: + break; + default: + prev (); + break; + } + } + inline TokenType current () { return tokens[index].type; } + inline TokenType previous () { + return tokens[(index - 1 + BUFFER_SIZE) % BUFFER_SIZE].type; + } + inline bool accept (TokenType type) { if (current () == type) { next (); @@ -129,13 +144,13 @@ public class Vala.Parser : CodeVisitor { switch (type) { case TokenType.CLOSE_BRACE: - prev (); + safe_prev (); report_parse_error (new ParseError.SYNTAX ("following block delimiter %s missing", type.to_string ())); return true; case TokenType.CLOSE_BRACKET: case TokenType.CLOSE_PARENS: case TokenType.SEMICOLON: - prev (); + safe_prev (); report_parse_error (new ParseError.SYNTAX ("following expression/statement delimiter %s missing", type.to_string ())); return true; default: @@ -1686,9 +1701,7 @@ public class Vala.Parser : CodeVisitor { try { skip_type (); } catch (ParseError e) { - prev (); - var token = current (); - next (); + var token = previous (); if (token == TokenType.DOT || token == TokenType.DOUBLE_COLON) { rollback (begin); return true;