-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Noticed this with the times module when my application was crashing calling format("h"), internally times is doing something akin to this:
https://gist.github.com/onionhammer/7518186
This seems to only happen when if: else: is ternary and the compared value is half of the maximum value + 1;
e.g. (pseudocode)
r = range[0..23]
return if r > 12: r - 12: else: r
r = range[0..45]
return if r > 23: r - 23 else: r
type TSomeRange = object
hour: range[0..23]
var value: string
#Works
var val6 = TSomeRange(hour: 6)
value = $(if val6.hour > 12: val6.hour - 12 else: val6.hour)
echo value
var val14 = TSomeRange(hour: 14)
value = $(if val14.hour > 12: val14.hour - 12 else: val14.hour)
echo value
#With 12, works
var val12 = TSomeRange(hour: 12)
if val12.hour > 12: value = $(val12.hour - 12) else: value = $val12.hour
echo value
#Crashes
value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
echo valueMetadata
Metadata
Assignees
Labels
No labels