From b5e410e408a3153b44dd8194bbc72245d5d1ddab Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 18 Nov 2021 14:34:30 +0900 Subject: [PATCH] fmt: format explicit map init with parameter (#12499) --- vlib/v/fmt/tests/maps_expected.vv | 6 ++++++ vlib/v/fmt/tests/maps_input.vv | 6 ++++++ vlib/v/parser/parser.v | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/vlib/v/fmt/tests/maps_expected.vv b/vlib/v/fmt/tests/maps_expected.vv index 122114a299..2cb1fcab7d 100644 --- a/vlib/v/fmt/tests/maps_expected.vv +++ b/vlib/v/fmt/tests/maps_expected.vv @@ -14,3 +14,9 @@ numbers := { 'sevenhundredseventyseven': 777 'fivethousandthreehundredtwentyseven': 5327 } + +explicit_init := map[string]string{} + +explicit_init_with_value := { + 'abc': 0 +} diff --git a/vlib/v/fmt/tests/maps_input.vv b/vlib/v/fmt/tests/maps_input.vv index 6eb783e285..a380a73ea7 100644 --- a/vlib/v/fmt/tests/maps_input.vv +++ b/vlib/v/fmt/tests/maps_input.vv @@ -14,3 +14,9 @@ numbers := { 'sevenhundredseventyseven': 777 'fivethousandthreehundredtwentyseven': 5327 } + +explicit_init := map[string]string{} + +explicit_init_with_value := map[string]int{ + 'abc': 0 +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 572aa61c23..dad416ad78 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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') } }