zig icon indicating copy to clipboard operation
zig copied to clipboard

Improve compile error when using std.io.getStdOutHandle

Open XI2vGMst opened this issue 1 year ago • 5 comments

After noticing that there are >4 issues made by people thinking this is a bug I thought it might be useful to improve the compile error to avoid more redundant issues. I would have liked to open a proposal issue for this, but that's not possible as of now. It is, however not breaking any code that isn't already broken, so I decided to make a pr anyways.

Related: https://github.com/ziglang/zig/issues/19864 https://github.com/ziglang/zig/issues/17186 https://github.com/ziglang/zig/issues/6845 https://github.com/ziglang/zig/issues/14203

XI2vGMst avatar May 07 '24 19:05 XI2vGMst

Wouldn't hurt to also add this for at least stderr.

Vexu avatar May 08 '24 09:05 Vexu

Good call, I don't know why I didn't think of that

XI2vGMst avatar May 08 '24 09:05 XI2vGMst

Done :+1:

XI2vGMst avatar May 08 '24 09:05 XI2vGMst

Hi! Apologies for this: stdin is also affected. Up to you all if you'll add this.

I'll just note here that in general, anything put in global that calls windows.peb() and windows.teb() (code) are affected. But since most that I found for this are already Windows specific, I don't think we should add the notice for these.

poypoyan avatar May 08 '24 09:05 poypoyan

I agree that the error shouldn't be returned by peb and teb, because this would also mean that the error message might have to be more generic, which would also make it less clear to the user if this is intended behavior or not. Additionally, this would not work for the current aarch64 workaround https://github.com/ziglang/zig/blob/master/lib/std/io.zig#L19 and cause more inconsistent behaveior from a user perspective. Let me know your thoughts on this!

XI2vGMst avatar May 08 '24 13:05 XI2vGMst

No thanks, it's fine as-is. It also breaks something that works fine on non-Windows targets.

andrewrk avatar May 09 '24 22:05 andrewrk

It also breaks something that works fine on non-Windows targets.

The errors are in Windows only branches.

Vexu avatar May 10 '24 05:05 Vexu

I see. It's still fine as-is. @inComptime is not meant to be used this way.

However, there is documentation missing on this function.

andrewrk avatar May 10 '24 21:05 andrewrk

You're right, I just checked the docs on @inComptime and it does say that it should be used primarily for e.g. performance improvements.

Should I just add the note about the functions not compiling on windows as a doc comment and open a new pr?

XI2vGMst avatar May 11 '24 10:05 XI2vGMst