I feel I fundamentally don't understand something about Nim, or that the code in my editor is not actually the code that is executed.
What I'm trying to achieve is an "early return pattern", where a proc exits if some precondition is not met. In this case the Option value gid should be present. So initially I had the two commented lines enabled. To recover my sanity I tried the "always return" logic.
In the sample below, vscode marks all lines below the return statement with warnings of unreachable code. When I run this code and place a breakpoint at the last line however, that last line is reached. What's more, is that in the debug Watches, gid is displayed as {val:0, has:false} and isNone is true
What could be going on here?
proc loadGid(level: Level, obj: LevelObjectEntity) =
let isNone = obj.gid.isNone
# if isNone:
# return
return
let gid = obj.gid.get
[..] more lines
It was something else entirely.
There are multiple LevelObjectEntity's to load, some of which have a gid. That's the whole reason why gid is an Option[unint32].
So for some calls to loadGid, the code would indeed return early, while for others it would run completely. The breakpoint hit for those calls where gid was present. Thanks!