Hi, can someone please help me to deal with this very strange error. I am trying to read data from the serial port and do something with it.
Here is the code snippet:
pub fn hasHello(buffer: []u8) bool {
return buffer.len > 0; // Stub
}
fn conn_waiting(conn: *BoardConn) void {
var buf: [64]u8 = std.mem.zeroes([64]u8);
// or
// var buf: [64]u8 = [1]u8{0} ** 64;
conn.lock.lock();
defer conn.lock.unlock();
while (conn.state == ConnState.Waiting and conn.running) {
conn.wait.timedWait(&conn.lock, 100 * std.time.ns_per_ms) catch {};
if (conn.port == null) {
std.log.warn("Port is null, closing...", .{});
conn.state = ConnState.Disconnected;
break;
}
const len = conn.port.?.read(&buf) catch |err| {
std.log.err("Failed to read from port: {s}", .{@errorName(err)});
conn.err = "Failed to read from port";
conn.state = ConnState.Disconnected;
break;
};
if (len > 0 || hasHello(&buf)) {
//board.zig:122:33: error: unable to resolve comptime value
// if (len > 0 || hasHello(&buf)) {
// ^~~~
//board.zig:122:32: note: types must be comptime-known
// if (len > 0 || hasHello(&buf)) {
continue; // Do something useful
}
}
}
I am completely lost on why Zig is trying to do anything comptime here. Also I checked the signature of the File.read() function and it looks very similar:
pub fn read(self: File, buffer: []u8) ReadError!usize {
But call to it compiles fine without any comptime errors.
I’ve tried using [*]u8, [*]const u8, []u8, [] const u8
but I get the same error with all of them.
I’m using Zig 0.14.0.