-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.10.0-dev.3877+3deb33fff
Steps to Reproduce
I can't create a very minimal example, as any very small examples i try to do with this results in different errors.
- run zig init-exe
- in src/main.zig use this source:
- link libc (for c_allocator)
const std = @import("std");
const Atomic = std.atomic.Atomic;
const ArrayListUnmanaged = std.ArrayListUnmanaged;
const S = struct {
func: *const fn (*anyopaque, *anyopaque) void,
};
pub fn testFunc(allocator: std.mem.Allocator, comptime CaptureType: type) !*CaptureType {
const Wrap = struct {
pub fn wrappedFunc(pointer: *anyopaque, context: *anyopaque) void {
var ptr = @ptrCast(*CaptureType, @alignCast(@alignOf(CaptureType), pointer));
ptr.func(context);
}
};
_ = Wrap;
var s = S{
.func = Wrap.wrappedFunc,
};
_ = s;
var ptr = try allocator.create(@sizeOf(CaptureType));
ptr.func = Wrap.wrappedFunc;
return ptr;
}
pub fn main() !void {
const TestStruct = struct {
v: u32 = 42069,
};
var p = try testFunc(
std.heap.c_allocator,
TestStruct,
);
_ = p;
}Expected Behavior
I would expect a more useful error message, here's the out of the code when compiled with stage 1:
(base) C:\Users\Admin\git\repro>zig build run -fstage1
.\src\main.zig:88:40: error: expected type 'type', found 'comptime_int'
var ptr = try allocator.create(@sizeOf(CaptureType));
^
.\src\main.zig:120:40: note: called from here
var jobContext = try JobContext.new(
^
.\src\main.zig:102:21: note: called from here
pub fn main() !void {
^
error: repro...
error: The following command exited with error code 1:
C:\app\zig\zig.exe build-exe -fstage1 C:\Users\Admin\git\repro\src\main.zig -lc --cache-dir C:\Users\Admin\git\repro\zig-cache --global-cache-dir C:\Users\Admin\AppData\Local\zig --name repro --enable-cache
error: the following build command failed with exit code 1:
C:\Users\Admin\git\repro\zig-cache\o\bb47ef463b4c6066ccf5ed3a8b788b20\build.exe C:\app\zig\zig.exe C:\Users\Admin\git\repro C:\Users\Admin\git\repro\zig-cache C:\Users\Admin\AppData\Local\zig run -fstage1 -fstage1
Actual Behavior
compiling with stage 2, this results in the following very unhelpful error
(base) C:\Users\Admin\git\repro>zig build run
error: repro...
error: The following command exited with error code 5:
C:\app\zig\zig.exe build-exe C:\Users\Admin\git\repro\src\main.zig -lc --cache-dir C:\Users\Admin\git\repro\zig-cache --global-cache-dir C:\Users\Admin\AppData\Local\zig --name repro --enable-cache
error: the following build command failed with exit code 5:
C:\Users\Admin\git\repro\zig-cache\o\df4b42c5bdd1b0e7384f7bac586625bc\build.exe C:\app\zig\zig.exe C:\Users\Admin\git\repro C:\Users\Admin\git\repro\zig-cache C
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior