From 2ca1463e159f7c38efbf82bb587d547d36a9dcd4 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 13 Jun 2023 22:06:44 -0500 Subject: [PATCH] added: parsing a `? T` with try to parse `T` --- core/conv/parse.onyx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/conv/parse.onyx b/core/conv/parse.onyx index a248b591..18dc22d0 100644 --- a/core/conv/parse.onyx +++ b/core/conv/parse.onyx @@ -4,6 +4,7 @@ use core.map use core.string use core.array use core.math +use core.memory use runtime #doc """ @@ -88,6 +89,15 @@ parse_any :: (target: rawptr, data_type: type_expr, to_parse: str, string_alloca d_info := cast(&Type_Info_Distinct) info; return parse_any(target, d_info.base_type, to_parse, string_allocator); } + + if info.kind == .Union && union_constructed_from(data_type, Optional) { + parsed_successful := parse_any(memory.ptr_add(target, info.alignment), info->as_union().variants[1].type, to_parse, string_allocator); + if !parsed_successful { + *cast(& u32) target = ~~ Optional(void).tag_enum.None; + } else { + *cast(& u32) target = ~~ Optional(void).tag_enum.Some; + } + } } } -- 2.25.1