From b4339f8d50e1ed03c54114c6af20cff8d153a108 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 4 May 2026 09:31:57 +0300 Subject: [PATCH] json2: decode fixes --- vlib/builtin/builtin_windows.c.v | 4 ++-- vlib/x/json2/decode.v | 33 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/vlib/builtin/builtin_windows.c.v b/vlib/builtin/builtin_windows.c.v index a86863200..f8beca2b5 100644 --- a/vlib/builtin/builtin_windows.c.v +++ b/vlib/builtin/builtin_windows.c.v @@ -46,7 +46,7 @@ pub type C.LPTSTR = &C.TCHAR pub type C.LPCTSTR = &C.TCHAR -fn C.WriteConsoleW(voidptr, &u16, u32, &u32, voidptr) bool +fn C.WriteConsoleW(voidptr, &u16, u32, voidptr, voidptr) bool fn C._setmode(int, int) int @@ -105,7 +105,7 @@ fn write_buf_to_console(fd int, buf &u8, buf_len int) bool { mut wide_ptr := wide_buf for remaining_chars > 0 { mut chars_written := u32(0) - if !C.WriteConsoleW(console_handle, wide_ptr, u32(remaining_chars), &chars_written, nil) + if !C.WriteConsoleW(console_handle, wide_ptr, u32(remaining_chars), voidptr(&chars_written), nil) || chars_written == 0 { return false } diff --git a/vlib/x/json2/decode.v b/vlib/x/json2/decode.v index 13303b27f..dd38fd056 100644 --- a/vlib/x/json2/decode.v +++ b/vlib/x/json2/decode.v @@ -1219,17 +1219,36 @@ fn (mut decoder Decoder) decode_map[V](mut val map[string]V) ! { decoder.decode_value(mut map_value)! } - $if V.unaliased_typ is $map { - // V is itself a map (alias) - skip assignment to avoid V compiler - // confusion about element type of nested map aliases. + $if V is $alias && V.unaliased_typ is $map { + // V is a map alias (e.g. `type SyntaxStyle = map[string]X`). + // V's checker reports `val[key]` as the unaliased element type + // while `map_value` keeps the alias type, so direct assignment + // fails to type-check. Skip to keep generic instantiations + // compilable; decoding into map-alias map values is unsupported. } $else $if K is string { - val[key_str] = map_value + $if V is $map { + val[key_str] = map_value.move() + } $else { + val[key_str] = map_value + } } $else $if K is rune { - val[rune(key_str.int())] = map_value + $if V is $map { + val[rune(key_str.int())] = map_value.move() + } $else { + val[rune(key_str.int())] = map_value + } } $else $if K is $int { - val[K(key_str.int())] = map_value + $if V is $map { + val[K(key_str.int())] = map_value.move() + } $else { + val[K(key_str.int())] = map_value + } } $else { - val[key_str] = map_value + $if V is $map { + val[key_str] = map_value.move() + } $else { + val[key_str] = map_value + } } } } else { -- 2.39.5