tvariantstack.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. discard """
  2. output: "came here"
  3. """
  4. #BUG
  5. type
  6. TAnyKind = enum
  7. nkInt,
  8. nkFloat,
  9. nkString
  10. PAny = ref TAny
  11. TAny = object
  12. case kind: TAnyKind
  13. of nkInt: intVal: int
  14. of nkFloat: floatVal: float
  15. of nkString: strVal: string
  16. TStack* = object
  17. list*: seq[TAny]
  18. proc newStack(): TStack =
  19. result.list = @[]
  20. proc push(Stack: var TStack, item: TAny) =
  21. var nSeq: seq[TAny] = @[item]
  22. for i in items(Stack.list):
  23. nSeq.add(i)
  24. Stack.list = nSeq
  25. proc pop(Stack: var TStack): TAny =
  26. result = Stack.list[0]
  27. Stack.list.delete(0)
  28. var stack = newStack()
  29. var s = TAny(kind: nkString, strVal: "test")
  30. stack.push(s)
  31. var nr = TAny(kind: nkInt, intVal: 78)
  32. stack.push(nr)
  33. var t = stack.pop()
  34. echo "came here"
  35. # another regression:
  36. type
  37. LexerToken* = enum
  38. ltYamlDirective, ltYamlVersion, ltTagDirective, ltTagShorthand,
  39. ltTagUri, ltUnknownDirective, ltUnknownDirectiveParams, ltEmptyLine,
  40. ltDirectivesEnd, ltDocumentEnd, ltStreamEnd, ltIndentation, ltQuotedScalar,
  41. ltScalarPart, ltBlockScalarHeader, ltBlockScalar, ltSeqItemInd, ltMapKeyInd,
  42. ltMapValInd, ltBraceOpen, ltBraceClose, ltBracketOpen, ltBracketClose,
  43. ltComma, ltLiteralTag, ltTagHandle, ltAnchor, ltAlias
  44. const tokensWithValue =
  45. {ltScalarPart, ltQuotedScalar, ltYamlVersion, ltTagShorthand, ltTagUri,
  46. ltUnknownDirective, ltUnknownDirectiveParams, ltLiteralTag, ltAnchor,
  47. ltAlias, ltBlockScalar}
  48. type
  49. TokenWithValue = object
  50. case kind: LexerToken
  51. of tokensWithValue:
  52. value: string
  53. of ltIndentation:
  54. indentation: int
  55. of ltTagHandle:
  56. handle, suffix: string
  57. else: discard
  58. proc sp(v: string): TokenWithValue =
  59. # test.nim(27, 17) Error: a case selecting discriminator 'kind' with value 'ltScalarPart' appears in the object construction, but the field(s) 'value' are in conflict with this value.
  60. TokenWithValue(kind: ltScalarPart, value: v)
  61. let a = sp("test")