tobjfield_analysis.nim 834 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. output: '''works'''
  3. """
  4. # bug #11095
  5. type
  6. MyVal[T] = object
  7. f: ptr T
  8. proc `=destroy`[T](x: var MyVal[T]) =
  9. if x.f != nil:
  10. dealloc(x.f)
  11. proc `=sink`[T](x1: var MyVal[T], x2: MyVal[T]) =
  12. if x1.f != x2.f:
  13. `=destroy`(x1)
  14. x1.f = x2.f
  15. proc `=`[T](x1: var MyVal[T], x2: MyVal[T]) {.error.}
  16. proc newVal[T](x: sink T): MyVal[T] =
  17. result.f = create(T)
  18. result.f[] = x
  19. proc set[T](x: var MyVal[T], val: T) =
  20. x.f[] = val
  21. proc sinkMe[T](x: sink MyVal[T]) =
  22. discard
  23. var flag = false
  24. proc main =
  25. var y = case flag
  26. of true:
  27. var x1 = newVal[float](1.0)
  28. var x2 = newVal[float](2.0)
  29. (newVal(x1), newVal(x2))
  30. of false:
  31. var x1 = newVal[float](1.0)
  32. var x2 = newVal[float](2.0)
  33. (newVal(x1), newVal(x2))
  34. sinkMe y[0]
  35. sinkMe y[1]
  36. echo "works"
  37. main()