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:
parent
e2398cafd2
commit
fe6197fe2d
|
@ -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('')
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
})
|
||||
|
|
|
@ -12,7 +12,7 @@ fn test_map_init_with_enum_keys() {
|
|||
mut st := St{}
|
||||
|
||||
st.m = {
|
||||
.ea: 'a',
|
||||
.ea: 'a'
|
||||
}
|
||||
|
||||
println(st.m)
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user