Skip to content

tests: harden skip-unused json2 test against helper refactors - #27537

Closed
enghitalo wants to merge 1 commit into
vlang:masterfrom
enghitalo:fix-skip-unused-json2-helper-symbol
Closed

tests: harden skip-unused json2 test against helper refactors#27537
enghitalo wants to merge 1 commit into
vlang:masterfrom
enghitalo:fix-skip-unused-json2-helper-symbol

Conversation

@enghitalo

Copy link
Copy Markdown
Contributor

Background

On #27535, the chatgpt-codex-connector review flagged that vlib/v/tests/skip_unused/generic_fn_instantiation_pruning_test.v would start failing. This PR fixes the underlying brittleness so the test no longer hard-codes a json2 implementation detail.

The bug

test_skip_unused_keeps_json2_embedded_struct_decode_helpers (regression for #26928) asserts that -skip-unused keeps generic json2 helpers reachable only through comptime $for field codegen. One assertion hard-coded the generated symbol of a specific helper:

assert res.output.contains('x__json2__create_value_from_optional_T_time__Time')

create_value_from_optional is a json2 implementation detail. #27535 removes it (the option payload is now built inline with $zero(field.typ.payload_type)), so the symbol disappears and this assertion fails.

Reproduction

Compile the test program to C and grep the symbols (this is exactly what the test does):

// issue_26928.v
module main
import time
import x.json2
struct Meta { created_at ?time.Time }
struct Req  { Meta name string }
fn main() { _ := json2.decode[Req]('{"name":"x"}') or { panic(err) } }
v -w -o - issue_26928.v | grep create_value_from_optional

The fix

Assert the symbol that actually decodes the ?time.Time payload of the embedded Metax__json2__Decoder_decode_value_T_time__Time — instead of a specific helper name. In this program time.Time only appears as that optional embedded field, so the instantiation is reachable only through comptime $for field codegen — exactly the skip-unused guarantee #26928 is about. Crucially, it is emitted whether or not the json2 helpers exist, so the test no longer breaks when they are refactored.

Testing

v -w test vlib/v/tests/skip_unused/generic_fn_instantiation_pruning_test.vpasses both:

This is independent of #27535 and green on master today; once it lands, #27535 just needs a rebase to pick it up.

🤖 Generated with Claude Code

…nused test

`test_skip_unused_keeps_json2_embedded_struct_decode_helpers` hard-coded the
generated symbol `x__json2__create_value_from_optional_T_time__Time`. That helper
is a json2 implementation detail: vlang#27535 replaces it with an inlined
`$zero(field.typ.payload_type)`, after which the symbol no longer exists and the
test fails.

Assert `x__json2__Decoder_decode_value_T_time__Time` instead -- the generic
instantiation that actually decodes the `?time.Time` payload of the embedded
`Meta` struct, reachable only through comptime `$for field` codegen. It is the
symbol skip-unused must keep (the point of issue vlang#26928), is present whether or
not the json2 helpers exist, and so the test no longer breaks when they are
refactored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@enghitalo

Copy link
Copy Markdown
Contributor Author

Folding this into #27535 instead — the test fix now travels with the change that removes the helper. Closing in favor of that single PR.

@enghitalo enghitalo closed this Jun 22, 2026
@enghitalo
enghitalo deleted the fix-skip-unused-json2-helper-symbol branch June 22, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant