Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker: fix structinit validation on nested generic Map[K]V #23332

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading