From 51125541c7ffcdec3f274afeea47413dc96d8e72 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Tue, 23 Feb 2021 08:51:00 +0100 Subject: [PATCH] parser: fix weird minus after comment parse error in arrays (#8912) --- vlib/v/fmt/tests/comments_embedded_keep.vv | 6 ++++++ vlib/v/parser/pratt.v | 1 + 2 files changed, 7 insertions(+) diff --git a/vlib/v/fmt/tests/comments_embedded_keep.vv b/vlib/v/fmt/tests/comments_embedded_keep.vv index a28f94bb39..4f8b36997b 100644 --- a/vlib/v/fmt/tests/comments_embedded_keep.vv +++ b/vlib/v/fmt/tests/comments_embedded_keep.vv @@ -14,4 +14,10 @@ fn only_comments_array() { fn array_pre_comments() { _ := [/* 2, */ 3] _ := [/* 4, */ /* 5, */ 6] + _ := [/* cmt */ -4] +} + +fn negative_num_after_comment_expr() { + // This caused a bug where the ´-´ was parsed as InfixExpr and not as part of an IntegerLiteral + _ := [1, /* cmt */ -4] } diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index 9dbd1e8252..0f6769b0ad 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -45,6 +45,7 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr { } .comment { node = p.comment() + return node } .dot { // .enum_val