Skip to content

Commit fe6197f

Browse files
authored
fmt: remove comma inside map_init using multi_line (#16007)
1 parent e2398ca commit fe6197f

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

vlib/v/fmt/fmt.v

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,11 +2305,6 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
23052305
f.write(': ')
23062306
f.write(strings.repeat(` `, max_field_len - skey.len))
23072307
f.expr(node.vals[i])
2308-
if key is ast.EnumVal && skey.starts_with('.') {
2309-
// enforce the use of `,` for maps with short enum keys, otherwise there is ambiguity
2310-
// when the values are struct values, and the code will no longer parse properly
2311-
f.write(',')
2312-
}
23132308
f.comments(node.comments[i], prev_line: node.vals[i].pos().last_line, has_nl: false)
23142309
f.writeln('')
23152310
}

vlib/v/fmt/tests/maps_expected.vv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ explicit_init_with_value := {
2222
}
2323

2424
headers := http.new_header_from_map({
25-
.content_type: 'application/json',
26-
.authorization: 'Bearer abcdef',
25+
.content_type: 'application/json'
26+
.authorization: 'Bearer abcdef'
2727
})

vlib/v/tests/map_init_with_enum_keys_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn test_map_init_with_enum_keys() {
1212
mut st := St{}
1313

1414
st.m = {
15-
.ea: 'a',
15+
.ea: 'a'
1616
}
1717

1818
println(st.m)

vlib/v/tests/map_init_with_multi_enum_keys_test.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum NestedFoo {
1414
fn test_map_init_with_multi_enum_keys() {
1515
mp := {
1616
Foo.a: 'A'
17-
.b: 'B',
17+
.b: 'B'
1818
}
1919
println(mp)
2020
assert mp[.a] == 'A'
@@ -26,10 +26,10 @@ fn test_nested_map_init_with_multi_enum_keys() {
2626
NestedFoo.a: NestedAbc({
2727
'A': 'AA'
2828
})
29-
.b: 'B',
29+
.b: 'B'
3030
.c: {
3131
'c': 'C'
32-
},
32+
}
3333
}
3434
println(mp)
3535
assert mp[.a]? == NestedAbc({

vlib/v/tests/vargs_with_enum_value_test.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn foo(n int, m ...map[Foo]int) {
1212

1313
fn test_vargs_with_enum_value() {
1414
foo(1, {
15-
.a: 1,
15+
.a: 1
1616
}, {
17-
.b: 2,
17+
.b: 2
1818
})
1919
}

0 commit comments

Comments
 (0)