| author | |
| committer | |
| log | 9343c31c3879514c890c9bfa2a1cd1a1f222ed6d |
| tree | 371a2fd2694adde2be6579563448e28e8facbfa5 |
| parent | 6bd54793060191ffce2c7492a90a40a30f9e2a1d |
Closes #162292 files changed, 18 insertions(+), 0 deletions(-)
src/Sema.zig+4| ... | ... | @@ -23301,6 +23301,7 @@ fn analyzeMinMax( |
| 23301 | 23301 | |
| 23302 | 23302 | if (cur_minmax == null) { |
| 23303 | 23303 | // No comptime operands - use the first operand as the starting value |
| 23304 | assert(bounds_status == .unknown); | |
| 23304 | 23305 | assert(runtime_idx == 0); |
| 23305 | 23306 | cur_minmax = operands[0]; |
| 23306 | 23307 | cur_minmax_src = runtime_src; |
| ... | ... | @@ -23309,6 +23310,9 @@ fn analyzeMinMax( |
| 23309 | 23310 | if (scalar_ty.isInt(mod)) { |
| 23310 | 23311 | cur_min_scalar = try scalar_ty.minInt(mod, scalar_ty); |
| 23311 | 23312 | cur_max_scalar = try scalar_ty.maxInt(mod, scalar_ty); |
| 23313 | bounds_status = .defined; | |
| 23314 | } else { | |
| 23315 | bounds_status = .non_integral; | |
| 23312 | 23316 | } |
| 23313 | 23317 | } |
| 23314 | 23318 |
test/behavior/maximum_minimum.zig+14| ... | ... | @@ -295,3 +295,17 @@ test "@min/@max notices bounds from vector types when element of comptime-known |
| 295 | 295 | try expectEqual(@as(u32, 1_000_000), max[0]); |
| 296 | 296 | // Cannot assert values at index 1 as one was undefined |
| 297 | 297 | } |
| 298 | ||
| 299 | test "@min/@max of signed and unsigned runtime integers" { | |
| 300 | var x: i32 = -1; | |
| 301 | var y: u31 = 1; | |
| 302 | ||
| 303 | const min = @min(x, y); | |
| 304 | const max = @max(x, y); | |
| 305 | ||
| 306 | comptime assert(@TypeOf(min) == i32); | |
| 307 | comptime assert(@TypeOf(max) == u31); | |
| 308 | ||
| 309 | try expectEqual(x, @min(x, y)); | |
| 310 | try expectEqual(y, @max(x, y)); | |
| 311 | } |