Skip to content

Instantly share code, notes, and snippets.

@flaviut
Last active August 29, 2015 13:58
Show Gist options
  • Save flaviut/10420337 to your computer and use it in GitHub Desktop.
Save flaviut/10420337 to your computer and use it in GitHub Desktop.
type
TTest* = object
pos*: range[0..15]
proc next(state: var TTest): int64 =
assert(state.pos >= 0 and state.pos < 16, "pos is " & $state.pos)
# Error: unhandled exception: state.pos >= 0 and state.pos < 16 pos is 140736480769200 [EAssertionFailed]
# 140736480769200 is incremented by a few million each execution
state.pos = (state.pos + 1) and 15
var state = TTest()
var accm: int64 = 0
for i in 1..100000000:
accm = (next state)
# discard (next state) works without issues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment