As I said in the previous post, I'm trying to create a "Any Value" case type. 
Another problem I have is supporting "seq[AnyValue]". Seq of anything else 
seems to work. Maybe it's a type recursion problem? Is there a work-around?

Here's the example:
    
    
    type
      AnyValueType* = enum
        avBool,
        # ...
        avBoolSeq,
        # ...
        avAnySeq
      
      AnyValue* = object
        case kind*: AnyValueType
        of avBool: boolValue*: bool
        # ...
        of avBoolSeq: boolSeqValue*: seq[bool]
        # ...
        of avAnySeq: anyseqValue*: seq[AnyValue]
    
    converter toBoolAnyValue*(v: bool): AnyValue {.inline, noSideEffect.} =
      result.kind = avBool
      result.boolValue = v
    
    converter toBoolSeqAnyValue*(v: seq[bool]): AnyValue {.inline, 
noSideEffect.} =
      result.kind = avBoolSeq
      result.boolSeqValue = v
    
    converter toSeqAnyValueAnyValue*(v: seq[AnyValue]): AnyValue {.inline, 
noSideEffect.} =
      result.kind = avAnySeq
      result.anyseqValue = v
    
    when isMainModule:
      let boolValue: bool = true
      let boolValueAV: AnyValue = boolValue
      let boolSeqValue: seq[bool] = @[boolValue]
      let boolSeqValueAV: AnyValue = boolSeqValue
      let anyseqValue: seq[AnyValue] = @[boolValueAV]
      let anyseqValueAV: AnyValue = anyseqValue
      
      assert(boolValueAV.boolValue == boolValue)
      assert(boolSeqValueAV.boolSeqValue == boolSeqValue)
      assert(anyseqValueAV.anyseqValue == anyseqValue) # Compiler bug :(
    

Reply via email to