1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: remove comma inside map_init using multi_line (#16007)

This commit is contained in:
yuyi 2022-10-09 13:39:30 +08:00 committed by GitHub
parent e2398cafd2
commit fe6197fe2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 13 deletions

View File

@ -2305,11 +2305,6 @@ pub fn (mut f Fmt) map_init(node ast.MapInit) {
f.write(': ')
f.write(strings.repeat(` `, max_field_len - skey.len))
f.expr(node.vals[i])
if key is ast.EnumVal && skey.starts_with('.') {
// enforce the use of `,` for maps with short enum keys, otherwise there is ambiguity
// when the values are struct values, and the code will no longer parse properly
f.write(',')
}
f.comments(node.comments[i], prev_line: node.vals[i].pos().last_line, has_nl: false)
f.writeln('')
}

View File

@ -22,6 +22,6 @@ explicit_init_with_value := {
}
headers := http.new_header_from_map({
.content_type: 'application/json',
.authorization: 'Bearer abcdef',
.content_type: 'application/json'
.authorization: 'Bearer abcdef'
})

View File

@ -12,7 +12,7 @@ fn test_map_init_with_enum_keys() {
mut st := St{}
st.m = {
.ea: 'a',
.ea: 'a'
}
println(st.m)

View File

@ -14,7 +14,7 @@ enum NestedFoo {
fn test_map_init_with_multi_enum_keys() {
mp := {
Foo.a: 'A'
.b: 'B',
.b: 'B'
}
println(mp)
assert mp[.a] == 'A'
@ -26,10 +26,10 @@ fn test_nested_map_init_with_multi_enum_keys() {
NestedFoo.a: NestedAbc({
'A': 'AA'
})
.b: 'B',
.b: 'B'
.c: {
'c': 'C'
},
}
}
println(mp)
assert mp[.a]? == NestedAbc({

View File

@ -12,8 +12,8 @@ fn foo(n int, m ...map[Foo]int) {
fn test_vargs_with_enum_value() {
foo(1, {
.a: 1,
.a: 1
}, {
.b: 2,
.b: 2
})
}