mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 15:13:08 +00:00
Merge pull request #16480 from r00ster91/embedfile
fix `@embedFile("")` not giving a proper error
This commit is contained in:
commit
1291f4aca4
@ -8041,7 +8041,7 @@ pub const CallModifier = enum {
|
|||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
{#header_open|@cDefine#}
|
{#header_open|@cDefine#}
|
||||||
<pre>{#syntax#}@cDefine(comptime name: []u8, value) void{#endsyntax#}</pre>
|
<pre>{#syntax#}@cDefine(comptime name: []const u8, value) void{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
||||||
</p>
|
</p>
|
||||||
@ -8085,7 +8085,7 @@ pub const CallModifier = enum {
|
|||||||
{#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#}
|
{#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_open|@cInclude#}
|
{#header_open|@cInclude#}
|
||||||
<pre>{#syntax#}@cInclude(comptime path: []u8) void{#endsyntax#}</pre>
|
<pre>{#syntax#}@cInclude(comptime path: []const u8) void{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
||||||
</p>
|
</p>
|
||||||
@ -8176,7 +8176,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
|
|||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
{#header_open|@compileError#}
|
{#header_open|@compileError#}
|
||||||
<pre>{#syntax#}@compileError(comptime msg: []u8) noreturn{#endsyntax#}</pre>
|
<pre>{#syntax#}@compileError(comptime msg: []const u8) noreturn{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
This function, when semantically analyzed, causes a compile error with the
|
This function, when semantically analyzed, causes a compile error with the
|
||||||
message {#syntax#}msg{#endsyntax#}.
|
message {#syntax#}msg{#endsyntax#}.
|
||||||
@ -8267,7 +8267,7 @@ test "main" {
|
|||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
{#header_open|@cUndef#}
|
{#header_open|@cUndef#}
|
||||||
<pre>{#syntax#}@cUndef(comptime name: []u8) void{#endsyntax#}</pre>
|
<pre>{#syntax#}@cUndef(comptime name: []const u8) void{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
This function can only occur inside {#syntax#}@cImport{#endsyntax#}.
|
||||||
</p>
|
</p>
|
||||||
@ -8607,7 +8607,7 @@ test "@hasDecl" {
|
|||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
{#header_open|@import#}
|
{#header_open|@import#}
|
||||||
<pre>{#syntax#}@import(comptime path: []u8) type{#endsyntax#}</pre>
|
<pre>{#syntax#}@import(comptime path: []const u8) type{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
This function finds a zig file corresponding to {#syntax#}path{#endsyntax#} and adds it to the build,
|
This function finds a zig file corresponding to {#syntax#}path{#endsyntax#} and adds it to the build,
|
||||||
if it is not already added.
|
if it is not already added.
|
||||||
|
|||||||
@ -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…
x
Reference in New Issue
Block a user