X Window: compilation error

Hi, I’m trying to rewrite one of my old hobby projects in Zig. The project uses X11 library for GUI. I ran into this error:

cimport.zig:3903:136: error: expected type 'usize', found 'c_int'
pub inline fn ScreenOfDisplay(dpy: anytype, scr: anytype) @TypeOf(&@import("std").zig.c_translation.cast(_XPrivDisplay, dpy).*.screens[scr]) {
                                                                                                                                       ^~~
cimport.zig:3903:136: note: unsigned 64-bit int cannot represent all possible signed 32-bit values
referenced by:
    DefaultColormap: cimport.zig:3882:67
    guiInit: gui.zig:106:17

Error points to this code:

   102          gd.display = xwin.XOpenDisplay(null).?;
   103          gd.screen = @intCast(isize, xwin.DefaultScreen(gd.display));
   104          xwin.XAllocNamedColor(
   105              gd.display,
   106              xwin.DefaultColormap(gd.display, xwin.DefaultScreen(gd.display)),
   107              "SteelBlue",
   108              &gd.fg_color, &color
   109          );

screen is isize. I tried different types for it, but had no success.

What could it be?
Something is wrong with my code?
Or maybe something is wrong with cimport.zig?

Fixed

   102          gd.display = xwin.XOpenDisplay(null).?;
   103          gd.screen = xwin.DefaultScreen(gd.display);
   104          _ = xwin.XAllocNamedColor(
   105              gd.display,
   106              xwin.DefaultColormap(gd.display, @intCast(usize, gd.screen)),
   107              "SteelBlue",
   108              &gd.fg_color, &color
   109          );

Hmm… after fixing some other compilation errors this one came back :frowning:

Minimal example that works:

const std = @import("std");
const x11 = @cImport({
    @cInclude("X11/Xlib.h");
});

pub fn main() void {
    var display: *x11.Display = undefined;
    var screen: c_int = 0;
    var c1: x11.XColor = undefined;
    var c2: x11.XColor = undefined;

    display = x11.XOpenDisplay(null).?;
    screen = x11.DefaultScreen(display);
    const dcm = x11.DefaultColormap(display, @intCast(usize, screen));
    std.debug.print("{}\n", .{dcm});
    const nc = x11.XAllocNamedColor(display, dcm, "SteelBlue", &c1, &c2);
    std.debug.print("{}\n", .{nc});
}
$ /opt/zig/zig build-exe x11.zig -lc -lX11
$ ./x11
32
1

But same code in the context of a larger program results in compilation error.

I have XAllocNamedColor thrice. I corrected only the first one, but compiler still pointed to it (which was already correct). After I fixed the other two XAllocNamedColor, everything is Ok.

reported the bug