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) } }