aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2022-01-08 02:02:01 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-01-08 14:30:11 -0500
commit4931b8dc93ee4a99a415dffab03d400e95d1a90a (patch)
tree8586196d647638d70dd7c3c3e657f9adeabdb39c /src/Sema.zig
parent3f586781b6c8d698468cc58ab64797097323c253 (diff)
downloadzig-4931b8dc93ee4a99a415dffab03d400e95d1a90a.tar.gz
zig-4931b8dc93ee4a99a415dffab03d400e95d1a90a.zip
stage2: @errorName sema+llvm
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 9ecac34c77..bcda9e73ea 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -10478,7 +10478,18 @@ fn zirBoolToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
const inst_data = sema.code.instructions.items(.data)[inst].un_node;
const src = inst_data.src();
- return sema.fail(block, src, "TODO: Sema.zirErrorName", .{});
+ _ = src;
+ const operand = sema.resolveInst(inst_data.operand);
+ const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
+
+ if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
+ const bytes = val.castTag(.@"error").?.data.name;
+ return sema.addStrLit(block, bytes);
+ }
+
+ // Similar to zirTagName, we have special AIR instruction for the error name in case an optimimzation pass
+ // might be able to resolve the result at compile time.
+ return block.addUnOp(.error_name, operand);
}
fn zirUnaryMath(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {