Skip to content

Conversation

IOKG04
Copy link
Contributor

@IOKG04 IOKG04 commented Sep 19, 2025

Currently an assertion fails when trying to compile code like the following.

const a = @max(@as(f32, 1.0), std.math.maxInt(u32));
// or
var f: f32 = 1.0;
_ = &f;
const b = @min(f, std.math.maxInt(u32));

As far as I can see, this happens because in sema.analyzeMinMax no source location is given to the coercion of std.math.maxInt(u32) to the result type (f32). Because std.math.maxInt(u32) isn't representable as an f32 without rounding, this will throw an error. The error code then asserts that there is a source location, which, as said before, there is not.

I fixed this by coercing the comptime known arguments a bit earlier, with a source location given.
Also I removed the coercion of the comptime known argument(s) to intermediate_scalar_ty later on, because they are already guarantied to be coerced into it.

fixes #25284

fixes ziglang#25284 by giving explicit source locations
to the now failable coercion(s).
@IOKG04 IOKG04 changed the title @min @max coerce comptime known arguments earlier sema: coerce comptime known arguments earlier for @min @max Sep 19, 2025
@IOKG04
Copy link
Contributor Author

IOKG04 commented Sep 25, 2025

I just noticed that I forgot to add tests so this doesn't regress. Will do when I'm back from school.

IOKG04 and others added 2 commits September 25, 2025 14:04
...my pc might've crashed while running these tests, I hope it's unrelated to this code.
...but I also kind of hope it is this code, cause then I don't got hardware problems at least.
@IOKG04
Copy link
Contributor Author

IOKG04 commented Sep 25, 2025

I wrote in one of the commit messages that running the tests crashed my pc.
As it turns out, that was cause .zig-cache took up ~a quarter tebbibyte, over-filling my drive..
Based on tests passing, I'd assume I just had an unlucky case with some weird bug.
Also heard from a friend that this is a kind of known issue, except it can't be replicated..

Well in case it helps with figuring it out, I'm using Arch Linux with a Ryzen 7 5800x, 32 GiBs of RAM and a 960 GiBs NVME SSD as my /home/ drive.

#25192 seems related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes: @min of maxInt + f32
1 participant