Skip to content

Commit ada763e

Browse files
author
Lukas Neubert
authored
fmt: remove parenthesis around single ident (#9696)
1 parent 9427c5f commit ada763e

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

vlib/builtin/array.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub fn (mut a array) pop() voidptr {
270270
}
271271
}
272272
new_len := a.len - 1
273-
last_elem := unsafe { &byte(a.data) + (new_len) * a.element_size }
273+
last_elem := unsafe { &byte(a.data) + new_len * a.element_size }
274274
a.len = new_len
275275
// NB: a.cap is not changed here *on purpose*, so that
276276
// further << ops on that array will be more efficient.

vlib/builtin/string_test.v

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn test_between() {
4343
fn test_compare() {
4444
a := 'Music'
4545
b := 'src'
46-
assert b >= (a)
46+
assert b >= a
4747
}
4848

4949
fn test_lt() {
@@ -53,12 +53,12 @@ fn test_lt() {
5353
d := 'b'
5454
e := 'aa'
5555
f := 'ab'
56-
assert a < (b)
56+
assert a < b
5757
assert !(b < c)
58-
assert c < (d)
58+
assert c < d
5959
assert !(d < e)
60-
assert c < (e)
61-
assert e < (f)
60+
assert c < e
61+
assert e < f
6262
}
6363

6464
fn test_ge() {
@@ -67,11 +67,11 @@ fn test_ge() {
6767
c := 'ab'
6868
d := 'abc'
6969
e := 'aaa'
70-
assert b >= (a)
71-
assert c >= (b)
72-
assert d >= (c)
70+
assert b >= a
71+
assert c >= b
72+
assert d >= c
7373
assert !(c >= d)
74-
assert e >= (a)
74+
assert e >= a
7575
}
7676

7777
fn test_compare_strings() {

vlib/os/os_windows.c.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const (
188188
const (
189189
sublang_neutral = 0x00
190190
sublang_default = 0x01
191-
lang_neutral = (sublang_neutral)
191+
lang_neutral = sublang_neutral
192192
)
193193

194194
// Ref - https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--12000-15999-

vlib/v/fmt/fmt.v

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,11 +2157,16 @@ pub fn (mut f Fmt) or_expr(node ast.OrExpr) {
21572157
}
21582158

21592159
pub fn (mut f Fmt) par_expr(node ast.ParExpr) {
2160-
f.write('(')
2161-
f.par_level++
2160+
requires_paren := node.expr !is ast.Ident
2161+
if requires_paren {
2162+
f.par_level++
2163+
f.write('(')
2164+
}
21622165
f.expr(node.expr)
2163-
f.par_level--
2164-
f.write(')')
2166+
if requires_paren {
2167+
f.par_level--
2168+
f.write(')')
2169+
}
21652170
}
21662171

21672172
pub fn (mut f Fmt) postfix_expr(node ast.PostfixExpr) {

vlib/v/fmt/tests/par_expr_expected.vv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
_ := (cond1 && cond2) || single_ident
3+
}

vlib/v/fmt/tests/par_expr_input.vv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
_ := (cond1 && cond2) || (single_ident)
3+
}

0 commit comments

Comments
 (0)