diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index a4f0ef269f9d9fd7a798bf58ce047871aec8218e..fa5b49db37d578931ef106b1e8c80a81c34791fb 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -27,7 +27,7 @@ pub const Cpu = std.Target.Cpu; /// On non-Windows targets, this is `null`. pub const subsystem: ?SubSystem = blk: { if (@hasDecl(@This(), "explicit_subsystem")) break :blk explicit_subsystem; - switch (os) { + switch (os.tag) { .windows => { if (is_test) { break :blk SubSystem.Console; @@ -406,9 +406,9 @@ pub const Version = struct { min: Version, max: Version, - pub fn includesVersion(self: LinuxVersionRange, ver: Version) bool { - if (self.min.compare(ver) == .gt) return false; - if (self.max.compare(ver) == .lt) return false; + pub fn includesVersion(self: Range, ver: Version) bool { + if (self.min.order(ver) == .gt) return false; + if (self.max.order(ver) == .lt) return false; return true; } }; diff --git a/src/analyze.cpp b/src/analyze.cpp index 1e667be5af0543b65fd3968be89fdc4a634a66f6..7712f0f7070ab008afae5a31b5a98394124ab636 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -649,11 +649,22 @@ ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) { } ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { + ZigType *result = get_optional_type2(g, child_type); + if (result == nullptr) { + codegen_report_errors_and_exit(g); + } + return result; +} + +ZigType *get_optional_type2(CodeGen *g, ZigType *child_type) { if (child_type->optional_parent != nullptr) { return child_type->optional_parent; } - assert(type_is_resolved(child_type, ResolveStatusSizeKnown)); + Error err; + if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) { + return nullptr; + } ZigType *entry = new_type_table_entry(ZigTypeIdOptional); diff --git a/src/analyze.hpp b/src/analyze.hpp index 8e441ef7697fc7ef1ed3df2c108a2dbdbca47cc1..fded1e40526644a1292a596ab07b3acd7438021c 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -34,6 +34,7 @@ ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type); ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type); ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id); ZigType *get_optional_type(CodeGen *g, ZigType *child_type); +ZigType *get_optional_type2(CodeGen *g, ZigType *child_type); ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size, ZigValue *sentinel); ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, diff --git a/src/ir.cpp b/src/ir.cpp index ef20c663b71a184fd9ca7188ebd8eb3307f6711f..86d85303c03ffcc12f2645bb8baa1a6a5df8ee24 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -24339,7 +24339,8 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy // default_value: var inner_fields[3]->special = ConstValSpecialStatic; - inner_fields[3]->type = get_optional_type(ira->codegen, struct_field->type_entry); + inner_fields[3]->type = get_optional_type2(ira->codegen, struct_field->type_entry); + if (inner_fields[3]->type == nullptr) return ErrorSemanticAnalyzeFail; memoize_field_init_val(ira->codegen, type_entry, struct_field); set_optional_payload(inner_fields[3], struct_field->init_val); diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index a3988cba6d4de766642fca7d477e6a8325e1af66..3ce44a89c431c4d161159b36e97f0ee6e4981ec7 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -386,3 +386,8 @@ test "@typeInfo does not force declarations into existence" { }; comptime expect(@typeInfo(S).Struct.fields.len == 1); } + +test "defaut value for a var-typed field" { + const S = struct { x: var }; + expect(@typeInfo(S).Struct.fields[0].default_value == null); +}