Skip to content

Commit ddcc22a

Browse files
author
Lukas Neubert
authored
fmt: fix removal of selective imported map key type (#10235)
1 parent 6b683d3 commit ddcc22a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

cmd/tools/vtest-cleancode.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const (
3535
'vlib/v/tests/interop_test.v', /* bad comment formatting */
3636
'vlib/v/tests/string_interpolation_test.v' /* TODO byteptr: &byte.str() behaves differently than byteptr.str() */,
3737
'vlib/v/gen/js/tests/js.v', /* local `hello` fn, gets replaced with module `hello` aliased as `hl` */
38-
'vlib/v/tests/map_enum_keys_test.v' /* temporary here, till PR#10235 is merged */,
3938
'examples/c_interop_wkhtmltopdf.v' /* &charptr --> &&char */,
4039
]
4140
vfmt_verify_list = [

vlib/v/fmt/fmt.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,9 @@ pub fn (mut f Fmt) lock_expr(node ast.LockExpr) {
20782078
pub fn (mut f Fmt) map_init(node ast.MapInit) {
20792079
if node.keys.len == 0 {
20802080
if node.typ > ast.void_type {
2081-
f.mark_types_import_as_used(node.typ)
2081+
sym := f.table.get_type_symbol(node.typ)
2082+
info := sym.info as ast.Map
2083+
f.mark_types_import_as_used(info.key_type)
20822084
f.write(f.table.type_to_str_using_aliases(node.typ, f.mod2alias))
20832085
} else {
20842086
// m = map{}

vlib/v/fmt/tests/import_selective_keep.vv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import math.complex { Complex }
2+
import gg { MouseButton }
3+
4+
fn keep_imported_enum_map_key() {
5+
bm := map[MouseButton]string{}
6+
}
27

38
fn main() {
49
assert *(&f64(&byte(&num) + __offsetof(Complex, re))) == 1.0

0 commit comments

Comments
 (0)