fmt: fix removal of attrs with comments afterwards (#9255)

pull/9257/head
Lukas Neubert 2021-03-11 21:44:33 +01:00 committed by GitHub
parent f276280d79
commit c40ab0db72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -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() {}

View File

@ -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() {}

View File

@ -240,10 +240,13 @@ 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
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])
p.scope.end_pos = p.tok.pos