Add a `@compileError` hint when trying to print from comptime
Fixes #14238.
While we can't cover every I/O function like this, lockStdErr covers std.debug.print and std.log.*, probably the most important places to leave a useful hint for newcomers to Zig.
can you add a test?
@nektro, there is no way to test compile errors in the standard library...
@nektro, there is no way to test compile errors in the standard library...
Out of curiosity, what's wrong with the following test file?
test/cases/compile_errors/io_in_comptime.zig:
const std = @import("std");
export fn a() void {
comptime std.debug.print("Printing in comptime isn't allowed!", .{});
}
// error
// backend=stage2
// target=native
//
// :?:?: error: I/O cannot be used from comptime. Consider using @compileError() or @compileLog().
// :?:?: note: called from here
// :?:?: note: called from here
// :4:29: note: called from here
Asking because I took a similar approach in the tests I wrote for #20748.
The tests in test/ exist to test the compiler implementation, not the standard library. So, you should remove those tests from #20748 -- I appreciate the effort, but that's not what that test suite is there for!
@andrewrk #14238 is still open, how else would that be solved?