fmt: keep same line comments after arr.sort() in vsh files (#8026)

pull/8029/head
Lukas Neubert 2021-01-13 19:10:17 +01:00 committed by GitHub
parent 2030875c0a
commit 8a8978fb01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 2 deletions

View File

@ -689,7 +689,7 @@ println(a) // [[[0, 0], [0, 2], [0, 0]], [[0, 0], [0, 0], [0, 0]]]
Sorting arrays of all kinds is very simple and intuitive. Special variables `a` and `b`
are used when providing a custom sorting condition.
```v nofmt
```v
mut numbers := [1, 3, 2]
numbers.sort() // 1, 2, 3
numbers.sort(a > b) // 3, 2, 1

View File

@ -5,3 +5,5 @@ println(x) // comment after
println('b')
// comment between
println('c')
mut numbers := [1, 3, 2]
numbers.sort() // 1, 2, 3

View File

@ -656,7 +656,8 @@ fn (mut g Gen) autofree_call_pregen(node ast.CallExpr) {
// g.writeln('// autofree_call_pregen()')
// Create a temporary var before fn call for each argument in order to free it (only if it's a complex expression,
// like `foo(get_string())` or `foo(a + b)`
mut free_tmp_arg_vars := g.is_autofree && !g.is_builtin_mod && node.args.len > 0 && !node.args[0].typ.has_flag(.optional) // TODO copy pasta checker.v
mut free_tmp_arg_vars := g.is_autofree && !g.is_builtin_mod && node.args.len > 0 &&
!node.args[0].typ.has_flag(.optional) // TODO copy pasta checker.v
if !free_tmp_arg_vars {
return
}

View File

@ -1500,6 +1500,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
//
end_pos := p.prev_tok.position()
pos := name_pos.extend(end_pos)
comments := p.eat_line_end_comments()
mcall_expr := ast.CallExpr{
left: left
name: field_name
@ -1514,6 +1515,7 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
pos: or_pos
}
scope: p.scope
comments: comments
}
if is_filter || field_name == 'sort' {
p.close_scope()