From 195f1612f85e8020d0d98f209067fa5bfb7426bd Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 3 Aug 2025 04:12:32 -0300 Subject: [PATCH] markused: fix option tracking on sumtype (fix #25025) (#25028) --- vlib/json/tests/json_decode_sumtype_option_test.v | 8 ++++++++ vlib/v/markused/walker.v | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 vlib/json/tests/json_decode_sumtype_option_test.v diff --git a/vlib/json/tests/json_decode_sumtype_option_test.v b/vlib/json/tests/json_decode_sumtype_option_test.v new file mode 100644 index 0000000000..537ce48920 --- /dev/null +++ b/vlib/json/tests/json_decode_sumtype_option_test.v @@ -0,0 +1,8 @@ +import json + +type Any = string | f32 | bool | ?int + +fn test_main() { + x := json.decode([]Any, '["hi", -9.8e7, true, null]')! + assert dump(x) == [Any('hi'), Any(f32(-9.8e+7)), Any(true), Any('')] +} diff --git a/vlib/v/markused/walker.v b/vlib/v/markused/walker.v index d8e1dc2d2d..690a797d3f 100644 --- a/vlib/v/markused/walker.v +++ b/vlib/v/markused/walker.v @@ -1161,6 +1161,9 @@ pub fn (mut w Walker) mark_by_sym(isym ast.TypeSymbol) { w.features.used_maps++ continue } + if typ.has_flag(.option) { + w.used_option++ + } w.mark_by_type(typ) } }