From 101440c1990de653bbfb19713915d86d7a5bc182 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 23 Aug 2019 17:14:51 -0400 Subject: add lazy value support for optional types this case works now: ```zig const Node = struct { node: ?*Node, }; ``` --- src/analyze.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 0b65210eea..5159dbb05a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -992,6 +992,7 @@ static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, Zi parent_type_val, is_zero_bits); } } + case LazyValueIdOptType: case LazyValueIdSliceType: *is_zero_bits = false; return ErrorNone; @@ -1017,6 +1018,7 @@ Error type_val_resolve_is_opaque_type(CodeGen *g, ConstExprValue *type_val, bool case LazyValueIdSliceType: case LazyValueIdPtrType: case LazyValueIdFnType: + case LazyValueIdOptType: *is_opaque_type = false; return ErrorNone; } @@ -1041,6 +1043,10 @@ static ReqCompTime type_val_resolve_requires_comptime(CodeGen *g, ConstExprValue LazyValuePtrType *lazy_ptr_type = reinterpret_cast(type_val->data.x_lazy); return type_val_resolve_requires_comptime(g, lazy_ptr_type->elem_type_val); } + case LazyValueIdOptType: { + LazyValueOptType *lazy_opt_type = reinterpret_cast(type_val->data.x_lazy); + return type_val_resolve_requires_comptime(g, lazy_opt_type->payload_type_val); + } case LazyValueIdFnType: { LazyValueFnType *lazy_fn_type = reinterpret_cast(type_val->data.x_lazy); if (lazy_fn_type->is_generic) @@ -1091,6 +1097,10 @@ static Error type_val_resolve_abi_align(CodeGen *g, ConstExprValue *type_val, si case LazyValueIdFnType: *abi_align = g->builtin_types.entry_usize->abi_align; return ErrorNone; + case LazyValueIdOptType: { + LazyValueOptType *lazy_opt_type = reinterpret_cast(type_val->data.x_lazy); + return type_val_resolve_abi_align(g, lazy_opt_type->payload_type_val, abi_align); + } } zig_unreachable(); } @@ -1104,6 +1114,7 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons case LazyValueIdAlignOf: zig_unreachable(); case LazyValueIdSliceType: // it has the len field + case LazyValueIdOptType: // it has the optional bit case LazyValueIdFnType: return OnePossibleValueNo; case LazyValueIdPtrType: { -- cgit v1.2.3