treassign.nim 692 B

12345678910111213141516171819202122232425262728293031323334353637
  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