fmt: format explicit map init with parameter (#12499)

pull/12503/head
zakuro 2021-11-18 14:34:30 +09:00 committed by GitHub
parent ae54cd78f5
commit b5e410e408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

View File

@ -14,3 +14,9 @@ numbers := {
'sevenhundredseventyseven': 777
'fivethousandthreehundredtwentyseven': 5327
}
explicit_init := map[string]string{}
explicit_init_with_value := {
'abc': 0
}

View File

@ -14,3 +14,9 @@ numbers := {
'sevenhundredseventyseven': 777
'fivethousandthreehundredtwentyseven': 5327
}
explicit_init := map[string]string{}
explicit_init_with_value := map[string]int{
'abc': 0
}

View File

@ -2034,6 +2034,11 @@ pub fn (mut p Parser) name_expr() ast.Expr {
if p.tok.kind == .rcbr {
p.next()
} else {
if p.pref.is_fmt {
map_init := p.map_init()
p.check(.rcbr)
return map_init
}
p.error('`}` expected; explicit `map` initialization does not support parameters')
}
}