this is discussed in <https://nim-lang.org/docs/strformat.html#limitations>

the workaround is
    
    
    import std/[strformat,strutils]
    import std/[enumutils,sugar]
    
    template printEnumMembers(E: typedesc[enum]) =
      for i in E.items:
        # it works
        #echo "[$1]: $2 -> ord: $3, $$: $4" % [$(i.symbolRank), 
$(i.symbolName), $(i.ord), $i]
        # it failed with undeclared identifie 'i'
        let i{.inject.}=i
        echo fmt"{i.symbolRank}: {i.symbolName} -> ord: {i.ord}, $: {i}"
    
    type Color = enum
      red, green, blue
    
    printEnumMembers Color
    
    
    Run

Reply via email to