odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
7.03k stars 624 forks source link

[checker] Report error when builtin `min`/`max` has only one numeric parameter #4494

Closed jakubtomsu closed 1 week ago

jakubtomsu commented 1 week ago

One parameter for min or max makes only sense when it's a type parameter. But when it's a regular numeric value (constant or variable), it's a no-op. I think in that case it's better to report an error to the user, because there is no practical reason to allow this and it makes it easier to notice a typo.

I ran into this multiple times in cases where I wrote foo = max(something) instead of foo = max(foo, something_else) to accumulate the maximum.

jakubtomsu commented 1 week ago

oops forgot enums exist

jakubtomsu commented 1 week ago

Wait hold on, the reported error found a bug no? I might be wrong about this, but looking at this code sample I think it should be max(Layer_Data_Type) instead of max(type)? In practice this condition would never trigger because max(type) just returns type https://github.com/odin-lang/Odin/blob/b3b276c47388a8a86d003fcda414280ac9687147/core/encoding/hxa/read.odin#L118-L122