mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
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".
This commit is contained in:
parent
279ebabd7d
commit
72ac37952e
2 changed files with 15 additions and 0 deletions
|
|
@ -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 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");
|
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) {
|
const embed_file = mod.embedFile(block.getFileScope(mod), name) catch |err| switch (err) {
|
||||||
error.ImportOutsidePkgPath => {
|
error.ImportOutsidePkgPath => {
|
||||||
return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
|
return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
|
||||||
|
|
|
||||||
11
test/cases/compile_errors/@embedFile_with_empty_path.zig
Normal file
11
test/cases/compile_errors/@embedFile_with_empty_path.zig
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const resource = @embedFile("");
|
||||||
|
|
||||||
|
export fn entry() usize {
|
||||||
|
return @sizeOf(@TypeOf(resource));
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
// backend=stage2
|
||||||
|
// target=native
|
||||||
|
//
|
||||||
|
// :1:29: error: file path name cannot be empty
|
||||||
Loading…
Add table
Reference in a new issue