aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorr00ster91 <r00ster91@proton.me>2023-07-21 23:08:04 +0200
committerr00ster91 <r00ster91@proton.me>2023-07-21 23:39:42 +0200
commit72ac37952e00184dbbf727fb3e7d3477d5637a87 (patch)
tree9b153f8aafbd9ffd6da4e325440eea71447b9124 /src
parent279ebabd7d8857393b893185c0d0108403c2edf2 (diff)
downloadzig-72ac37952e00184dbbf727fb3e7d3477d5637a87.tar.gz
zig-72ac37952e00184dbbf727fb3e7d3477d5637a87.zip
fix @embedFile("") not giving a proper error
Currently, in a debug build of the compiler, `@embedFile("")` is a crash; in a release build the compiler, `@embedFile("")` is "error: unable to open '': OutOfMemory".
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 38d59f4f39..0fcc914596 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -12633,6 +12633,10 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known");
+ if (name.len == 0) {
+ return sema.fail(block, operand_src, "file path name cannot be empty", .{});
+ }
+
const embed_file = mod.embedFile(block.getFileScope(mod), name) catch |err| switch (err) {
error.ImportOutsidePkgPath => {
return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});