From 4e323c091fc294546eba532a4bc1deb3bb40e0bb Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 25 Mar 2026 16:42:21 +0300 Subject: [PATCH] json2: fix c error when using both json2.decode[json2.Any] and json2.encode (fixes #24128) --- .../tests/decode_map_any_regression_test.v | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/vlib/x/json2/tests/decode_map_any_regression_test.v b/vlib/x/json2/tests/decode_map_any_regression_test.v index 15d87b074..fdd904112 100644 --- a/vlib/x/json2/tests/decode_map_any_regression_test.v +++ b/vlib/x/json2/tests/decode_map_any_regression_test.v @@ -1,5 +1,36 @@ import x.json2 +fn decode_any_issue_24128(j string) !json2.Any { + return json2.decode[json2.Any](j) +} + +fn decode_map_issue_24128(j string) !map[string]json2.Any { + return json2.decode[map[string]json2.Any](j) +} + +fn test_decode_any_and_map_any_in_same_program() { + for payload in [ + '{}', + '{"a":"b"}', + '{"a":1}', + '{"a":3.14}', + '{"a":{"b":"c"}}', + '{"a":true}', + ] { + decoded_any := decode_any_issue_24128(payload)! + decoded_map := decode_map_issue_24128(payload)! + + match decoded_any { + map[string]json2.Any { + assert decoded_any.str() == decoded_map.str() + } + else { + assert false + } + } + } +} + fn test_decode_map_any_keeps_numeric_values() { payload := { 'sub': json2.Any('453636') -- 2.39.5