From c40ab0db72d8111a15849b88971ff8a62db3e99b Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Thu, 11 Mar 2021 21:44:33 +0100 Subject: [PATCH] fmt: fix removal of attrs with comments afterwards (#9255) --- vlib/v/fmt/tests/attrs_expected.vv | 5 +++++ vlib/v/fmt/tests/attrs_input.vv | 4 ++++ vlib/v/parser/parser.v | 7 +++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vlib/v/fmt/tests/attrs_expected.vv b/vlib/v/fmt/tests/attrs_expected.vv index ec76cea00a..1660ee55db 100644 --- a/vlib/v/fmt/tests/attrs_expected.vv +++ b/vlib/v/fmt/tests/attrs_expected.vv @@ -2,3 +2,8 @@ [tom: 'jerry'] [direct_array_access; inline; unsafe] fn heavily_tagged() {} + +// console attribute for easier diagnostics on windows +// also it's not safe to use +[console; unsafe] +fn dangerous_console() {} diff --git a/vlib/v/fmt/tests/attrs_input.vv b/vlib/v/fmt/tests/attrs_input.vv index 4190d27689..bfffc55c99 100644 --- a/vlib/v/fmt/tests/attrs_input.vv +++ b/vlib/v/fmt/tests/attrs_input.vv @@ -4,3 +4,7 @@ [unsafe] [tom: 'jerry'] fn heavily_tagged() {} + +[console] // console attribute for easier diagnostics on windows +[unsafe] // also it's not safe to use +fn dangerous_console() {} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 5e20e5ac7d..988ab1837a 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -240,9 +240,12 @@ pub fn (mut p Parser) parse() ast.File { break } // println('stmt at ' + p.tok.str()) - stmts << p.top_stmt() + stmt := p.top_stmt() // clear the attributes after each statement - p.attrs = [] + if !(stmt is ast.ExprStmt && (stmt as ast.ExprStmt).expr is ast.Comment) { + p.attrs = [] + } + stmts << stmt } // println('nr stmts = $stmts.len') // println(stmts[0])