Skip to content

Commit 2112bb8

Browse files
authored
checker: fix structinit validation on nested generic Map[K]V (fix #23329) (#23332)
1 parent 734bb00 commit 2112bb8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

vlib/v/checker/fn.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,8 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
15091509
if call_arg.expr is ast.MapInit && e_sym.kind == .struct {
15101510
c.error('cannot initialize a struct with a map', call_arg.pos)
15111511
continue
1512-
} else if call_arg.expr is ast.StructInit && e_sym.kind == .map {
1512+
} else if call_arg.expr is ast.StructInit && e_sym.kind == .map
1513+
&& !call_arg.expr.typ.has_flag(.generic) {
15131514
c.error('cannot initialize a map with a struct', call_arg.pos)
15141515
continue
15151516
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import x.json2
2+
3+
struct CrossVerifyResult {
4+
confusion_matrix_map map[string]map[string]f64
5+
}
6+
7+
fn test_main() {
8+
x := json2.decode[CrossVerifyResult]('') or {
9+
assert err.msg().contains('invalid token')
10+
return
11+
}
12+
assert false
13+
}

0 commit comments

Comments
 (0)