mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fmt: fix parens around reference module prefix expressions (#18416)
This commit is contained in:
parent
37386697a3
commit
7f178d4662
@ -2629,9 +2629,9 @@ pub fn (mut f Fmt) postfix_expr(node ast.PostfixExpr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) prefix_expr(node ast.PrefixExpr) {
|
pub fn (mut f Fmt) prefix_expr(node ast.PrefixExpr) {
|
||||||
|
if node.right is ast.ParExpr {
|
||||||
|
if node.op == .not && node.right.expr is ast.InfixExpr {
|
||||||
// !(a in b) => a !in b, !(a is b) => a !is b
|
// !(a in b) => a !in b, !(a is b) => a !is b
|
||||||
if node.op == .not && node.right is ast.ParExpr {
|
|
||||||
if node.right.expr is ast.InfixExpr {
|
|
||||||
if node.right.expr.op in [.key_in, .not_in, .key_is, .not_is]
|
if node.right.expr.op in [.key_in, .not_in, .key_is, .not_is]
|
||||||
&& node.right.expr.right !is ast.InfixExpr {
|
&& node.right.expr.right !is ast.InfixExpr {
|
||||||
f.expr(node.right.expr.left)
|
f.expr(node.right.expr.left)
|
||||||
@ -2645,6 +2645,14 @@ pub fn (mut f Fmt) prefix_expr(node ast.PrefixExpr) {
|
|||||||
f.expr(node.right.expr.right)
|
f.expr(node.right.expr.right)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if node.op == .amp && node.right.expr is ast.Ident {
|
||||||
|
// Reference prefix ParExpr. E.g.: `a := &(modname.constname)`
|
||||||
|
f.write(node.op.str())
|
||||||
|
f.write('(')
|
||||||
|
f.expr(node.right)
|
||||||
|
f.or_expr(node.or_block)
|
||||||
|
f.write(')')
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.write(node.op.str())
|
f.write(node.op.str())
|
||||||
|
13
vlib/v/fmt/tests/module_ref_type_keep.vv
Normal file
13
vlib/v/fmt/tests/module_ref_type_keep.vv
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
module ast
|
||||||
|
|
||||||
|
struct MyChar {
|
||||||
|
c string
|
||||||
|
}
|
||||||
|
|
||||||
|
const a_char = MyChar{
|
||||||
|
c: 'a'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
mut b := &(ast.a_char)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user