Skip to content

Commit

Permalink
checker: fix structinit validation on nested generic Map[K]V (fix vla…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 1, 2025
1 parent 734bb00 commit 2112bb8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions vlib/x/json2/tests/decode_map_of_map_test.v
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2112bb8

Please sign in to comment.