| author | |
| committer | |
| log | 0977e4140768447e57474792ff42d056a8f2e0ed |
| tree | 67c87304105e594f6f1763077d607abf19e8a466 |
| parent | 60ea87340e7a7157bedbb43d60804ff0fb191ef9 |
| signature | Commit is signed but in an unrecognized format. |
3 files changed, 14 insertions(+), 1 deletions(-)
src-self-hosted/astgen.zig+5-1| ... | @@ -600,7 +600,11 @@ const CondKind = union(enum) { | ... | @@ -600,7 +600,11 @@ const CondKind = union(enum) { |
| 600 | fn thenSubScope(self: CondKind, mod: *Module, then_scope: *Scope.GenZIR, src: usize, payload_node: ?*ast.Node) !*Scope { | 600 | fn thenSubScope(self: CondKind, mod: *Module, then_scope: *Scope.GenZIR, src: usize, payload_node: ?*ast.Node) !*Scope { |
| 601 | if (self == .bool) return &then_scope.base; | 601 | if (self == .bool) return &then_scope.base; |
| 602 | 602 | ||
| 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 | }; | ||
| 604 | const is_ptr = payload.ptr_token != null; | 608 | const is_ptr = payload.ptr_token != null; |
| 605 | const ident_node = payload.value_symbol.castTag(.Identifier).?; | 609 | const ident_node = payload.value_symbol.castTag(.Identifier).?; |
| 606 | 610 |
src-self-hosted/zir.zig+4| ... | @@ -225,6 +225,8 @@ pub const Inst = struct { | ... | @@ -225,6 +225,8 @@ pub const Inst = struct { |
| 225 | unwrap_err_safe, | 225 | unwrap_err_safe, |
| 226 | /// Same as previous, but without safety checks. Used for orelse, if and while | 226 | /// Same as previous, but without safety checks. Used for orelse, if and while |
| 227 | unwrap_err_unsafe, | 227 | unwrap_err_unsafe, |
| 228 | /// Takes a *E!T and raises a compiler error if T != void | ||
| 229 | ensure_err_payload_void, | ||
| 228 | 230 | ||
| 229 | pub fn Type(tag: Tag) type { | 231 | pub fn Type(tag: Tag) type { |
| 230 | return switch (tag) { | 232 | return switch (tag) { |
| ... | @@ -259,6 +261,7 @@ pub const Inst = struct { | ... | @@ -259,6 +261,7 @@ pub const Inst = struct { |
| 259 | .unwrap_optional_unsafe, | 261 | .unwrap_optional_unsafe, |
| 260 | .unwrap_err_safe, | 262 | .unwrap_err_safe, |
| 261 | .unwrap_err_unsafe, | 263 | .unwrap_err_unsafe, |
| 264 | .ensure_err_payload_void, | ||
| 262 | => UnOp, | 265 | => UnOp, |
| 263 | 266 | ||
| 264 | .add, | 267 | .add, |
| ... | @@ -398,6 +401,7 @@ pub const Inst = struct { | ... | @@ -398,6 +401,7 @@ pub const Inst = struct { |
| 398 | .unwrap_err_safe, | 401 | .unwrap_err_safe, |
| 399 | .unwrap_err_unsafe, | 402 | .unwrap_err_unsafe, |
| 400 | .ptr_type, | 403 | .ptr_type, |
| 404 | .ensure_err_payload_void, | ||
| 401 | => false, | 405 | => false, |
| 402 | 406 | ||
| 403 | .@"break", | 407 | .@"break", |
src-self-hosted/zir_sema.zig+5| ... | @@ -112,6 +112,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! | ... | @@ -112,6 +112,7 @@ pub fn analyzeInst(mod: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError! |
| 112 | .unwrap_optional_unsafe => return analyzeInstUnwrapOptional(mod, scope, old_inst.castTag(.unwrap_optional_unsafe).?, false), | 112 | .unwrap_optional_unsafe => return analyzeInstUnwrapOptional(mod, scope, old_inst.castTag(.unwrap_optional_unsafe).?, false), |
| 113 | .unwrap_err_safe => return analyzeInstUnwrapErr(mod, scope, old_inst.castTag(.unwrap_err_safe).?, true), | 113 | .unwrap_err_safe => return analyzeInstUnwrapErr(mod, scope, old_inst.castTag(.unwrap_err_safe).?, true), |
| 114 | .unwrap_err_unsafe => return analyzeInstUnwrapErr(mod, scope, old_inst.castTag(.unwrap_err_unsafe).?, false), | 114 | .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).?), | ||
| 115 | } | 116 | } |
| 116 | } | 117 | } |
| 117 | 118 | ||
| ... | @@ -735,6 +736,10 @@ fn analyzeInstUnwrapErr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, saf | ... | @@ -735,6 +736,10 @@ fn analyzeInstUnwrapErr(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp, saf |
| 735 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErr", .{}); | 736 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstUnwrapErr", .{}); |
| 736 | } | 737 | } |
| 737 | 738 | ||
| 739 | fn analyzeInstEnsureErrPayloadVoid(mod: *Module, scope: *Scope, unwrap: *zir.Inst.UnOp) InnerError!*Inst { | ||
| 740 | return mod.fail(scope, unwrap.base.src, "TODO implement analyzeInstEnsureErrPayloadVoid", .{}); | ||
| 741 | } | ||
| 742 | |||
| 738 | fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst { | 743 | fn analyzeInstFnType(mod: *Module, scope: *Scope, fntype: *zir.Inst.FnType) InnerError!*Inst { |
| 739 | const return_type = try resolveType(mod, scope, fntype.positionals.return_type); | 744 | const return_type = try resolveType(mod, scope, fntype.positionals.return_type); |
| 740 | 745 |