From d4fed2da95c5914923b90f8f33d1d726d2997e5b Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 1 Jan 2025 09:30:45 -0300 Subject: [PATCH] fix --- vlib/v/checker/fn.v | 3 ++- vlib/x/json2/tests/decode_map_of_map_test.v | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 vlib/x/json2/tests/decode_map_of_map_test.v diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 92a27035e0c2ea..bf2287c0354a1b 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1509,7 +1509,8 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. if call_arg.expr is ast.MapInit && e_sym.kind == .struct { c.error('cannot initialize a struct with a map', call_arg.pos) continue - } else if call_arg.expr is ast.StructInit && e_sym.kind == .map { + } else if call_arg.expr is ast.StructInit && e_sym.kind == .map + && !call_arg.expr.typ.has_flag(.generic) { c.error('cannot initialize a map with a struct', call_arg.pos) continue } diff --git a/vlib/x/json2/tests/decode_map_of_map_test.v b/vlib/x/json2/tests/decode_map_of_map_test.v new file mode 100644 index 00000000000000..aa57b54e83d77d --- /dev/null +++ b/vlib/x/json2/tests/decode_map_of_map_test.v @@ -0,0 +1,13 @@ +import x.json2 + +struct CrossVerifyResult { + confusion_matrix_map map[string]map[string]f64 +} + +fn test_main() { + x := json2.decode[CrossVerifyResult]('') or { + assert err.msg().contains('invalid token') + return + } + assert false +}