| author | |
| committer | |
| log | 72ac37952e00184dbbf727fb3e7d3477d5637a87 |
| tree | 9b153f8aafbd9ffd6da4e325440eea71447b9124 |
| parent | 279ebabd7d8857393b893185c0d0108403c2edf2 |
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".2 files changed, 15 insertions(+), 0 deletions(-)
src/Sema.zig+4| ... | ... | @@ -12633,6 +12633,10 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 12633 | 12633 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 12634 | 12634 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known"); |
| 12635 | 12635 | |
| 12636 | if (name.len == 0) { | |
| 12637 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | |
| 12638 | } | |
| 12639 | ||
| 12636 | 12640 | const embed_file = mod.embedFile(block.getFileScope(mod), name) catch |err| switch (err) { |
| 12637 | 12641 | error.ImportOutsidePkgPath => { |
| 12638 | 12642 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); |
test/cases/compile_errors/@embedFile_with_empty_path.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const resource = @embedFile(""); | |
| 2 | ||
| 3 | export fn entry() usize { | |
| 4 | return @sizeOf(@TypeOf(resource)); | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :1:29: error: file path name cannot be empty |