A common source of remote exploits in Nim is that of `enum` conversions done 
like so:
    
    
    type X = enum
      Z
    
    var a = 42
    var b = X(a)
    
    
    Run

This will fail with a `RangeDefect` which subsequently crashes the application 
- unfortunately it gets used liberally in code we review, often when dealing 
with untrusted data, for example coming from the network or a file.

The (fairly) safe way around this is of course a `case` expression:
    
    
    case a of
    ord(Z): Z
    else: ...
    
    
    Run

but it gets tedious - any better alternatives out there? A few non-starters 
include try/catch (`Defect` cannot be caught in some dialects of Nim), low/high 
checks (doesn't work with gappy enums).

Winner gets an entry in the [style 
guide](https://status-im.github.io/nim-style-guide/) :)

Reply via email to