treassign.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. discard """
  2. output: "SUCCESS"
  3. """
  4. type
  5. BasicNumber = object of RootObj
  6. value: float32
  7. RefChild* = ref object
  8. curr*: TokenObject
  9. Token* {.pure.} = enum
  10. foo,
  11. bar,
  12. TokenObject = object
  13. case kind*: Token
  14. of Token.foo:
  15. foo*: string
  16. of Token.bar:
  17. bar*: BasicNumber
  18. var t = RefChild()
  19. t.curr = TokenObject(kind: Token.bar, bar: BasicNumber(value: 12.34))
  20. t.curr = TokenObject(kind: Token.foo, foo: "foo")
  21. echo "SUCCESS"
  22. proc passToVar(x: var Token) = discard
  23. {.cast(uncheckedAssign).}:
  24. passToVar(t.curr.kind)
  25. t.curr = TokenObject(kind: t.curr.kind, foo: "abc")
  26. t.curr.kind = Token.foo
  27. block:
  28. type
  29. TokenKind = enum
  30. strLit, intLit
  31. Token = object
  32. case kind*: TokenKind
  33. of strLit:
  34. s*: string
  35. of intLit:
  36. i*: int64
  37. var t = Token(kind: strLit, s: "abc")
  38. {.cast(uncheckedAssign).}:
  39. # inside the 'cast' section it is allowed to assign to the 't.kind' field directly:
  40. t.kind = intLit
  41. {.cast(uncheckedAssign).}:
  42. t.kind = strLit