From 095e13a5562edb4804d2d4deee9e2eae775c00b4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:26 +0300 Subject: [PATCH] cgen: v panic by sync__pool__process_in_thread (fixes #26826) --- vlib/v/gen/c/fn.v | 2 +- ..._sumtype_smartcast_json_decode_call_test.v | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/conditions/matches/match_sumtype_smartcast_json_decode_call_test.v diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index f3c4c5cbe..cc2429b94 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -5570,7 +5570,7 @@ fn (mut g Gen) call_args(node ast.CallExpr) { if resolved_arg_type != 0 { expected_types[i] = resolved_arg_type } - } else if arg.expr.obj.smartcasts.len > 0 { + } else if i < expected_types.len && arg.expr.obj.smartcasts.len > 0 { exp_sym := g.table.sym(expected_types[i]) orig_sym := g.table.sym(arg.expr.obj.orig_type) if !expected_types[i].has_option_or_result() && orig_sym.kind != .interface diff --git a/vlib/v/tests/conditions/matches/match_sumtype_smartcast_json_decode_call_test.v b/vlib/v/tests/conditions/matches/match_sumtype_smartcast_json_decode_call_test.v new file mode 100644 index 000000000..b7360eeb0 --- /dev/null +++ b/vlib/v/tests/conditions/matches/match_sumtype_smartcast_json_decode_call_test.v @@ -0,0 +1,29 @@ +import json + +type Issue26826Value = Issue26826Nil | string + +struct Issue26826Nil {} + +struct Issue26826Session { + id string +} + +fn issue_26826_load(v Issue26826Value) !Issue26826Session { + match v { + string { + loaded_session := json.decode(Issue26826Session, v)! + return loaded_session + } + else { + return error('bad') + } + } +} + +fn test_match_sumtype_smartcast_json_decode_call() { + session := issue_26826_load('{"id":"a"}') or { + assert false, err.msg() + return + } + assert session.id == 'a' +} -- 2.39.5