authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-18 10:36:57+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-18 10:36:57+03:00
log0977e4140768447e57474792ff42d056a8f2e0ed
tree67c87304105e594f6f1763077d607abf19e8a466
parent60ea87340e7a7157bedbb43d60804ff0fb191ef9
signaturelock-open Commit is signed but in an unrecognized format.

stage2: ensure discarded error union payload is void


3 files changed, 14 insertions(+), 1 deletions(-)

src-self-hosted/astgen.zig+5-1
......@@ -600,7 +600,11 @@ const CondKind = union(enum) {
600600 fn thenSubScope(self: CondKind, mod: *Module, then_scope: *Scope.GenZIR, src: usize, payload_node: ?*ast.Node) !*Scope {
601601 if (self == .bool) return &then_scope.base;
602602
603 const payload = payload_node.?.castTag(.PointerPayload).?;
603 const payload = payload_node.?.castTag(.PointerPayload) orelse {
604 // condition is error union and payload is not explicitly ignored
605 _ = try addZIRUnOp(mod, &then_scope.base, src, .ensure_err_payload_void, self.err_union.?);
606 return &then_scope.base;
607 };
604608 const is_ptr = payload.ptr_token != null;
605609 const ident_node = payload.value_symbol.castTag(.Identifier).?;
606610
src-self-hosted/zir.zig+4
......@@ -225,6 +225,8 @@ pub const Inst = struct {
225225 unwrap_err_safe,
226226 /// Same as previous, but without safety checks. Used for orelse, if and while
227227 unwrap_err_unsafe,
228 /// Takes a *E!T and raises a compiler error if T != void
229 ensure_err_payload_void,
228230
229231 pub fn Type(tag: Tag) type {
230232 return switch (tag) {
......@@ -259,6 +261,7 @@ pub const Inst = struct {
259261 .unwrap_optional_unsafe,
260262 .unwrap_err_safe,
261263 .unwrap_err_unsafe,
264 .ensure_err_payload_void,
262265 => UnOp,
263266
264267 .add,
......@@ -398,6 +401,7 @@ pub const Inst = struct {
398401 .unwrap_err_safe,
399402 .unwrap_err_unsafe,
400403 .ptr_type,
404 .ensure_err_payload_void,
401405 => false,
402406
403407 .@"break",
src-self-hosted/zir_sema.zig+5
......@@ -112,6 +112,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!
112112 .unwrap_optional_unsafe => return analyzeInstUnwrapOptional(mod, scope, old_inst.castTag(.unwrap_optional_unsafe).?, false),
113113 .unwrap_err_safe => return analyzeInstUnwrapErr(mod, scope, old_inst.castTag(.unwrap_err_safe).?, true),
114114 .unwrap_err_unsafe => return analyzeInstUnwrapErr(mod, scope, old_inst.castTag(.unwrap_err_unsafe).?, false),
115 .ensure_err_payload_void => return analyzeInstEnsureErrPayloadVoid(mod, scope, old_inst.castTag(.ensure_err_payload_void).?),
115116 }
116117}
117118
......@@ -735,6 +736,10 @@ fn analyzeInstUnwrapErr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, saf
735736 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErr", .{});
736737}
737738
739fn analyzeInstEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst {
740 return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstEnsureErrPayloadVoid", .{});
741}
742
738743fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst {
739744 const return_type = try resolveType(mod, scope, fntype.positionals.return_type);
740745