tcgbug.nim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. discard """
  2. output: '''
  3. success
  4. M1 M2
  5. ok
  6. '''
  7. """
  8. type
  9. TObj = object
  10. x, y: int
  11. PObj = ref TObj
  12. proc p(a: PObj) =
  13. a.x = 0
  14. proc q(a: var PObj) =
  15. a.p()
  16. var
  17. a: PObj
  18. new(a)
  19. q(a)
  20. # bug #914
  21. when defined(windows):
  22. var x = newWideCString("Hello")
  23. echo "success"
  24. # bug #833
  25. type
  26. PFuture*[T] = ref object
  27. value*: T
  28. finished*: bool
  29. cb: proc (future: PFuture[T]) {.closure.}
  30. var k = PFuture[void]()
  31. ##bug #9297 and #13281
  32. import strutils
  33. type
  34. MyKind = enum
  35. M1, M2, M3
  36. MyObject {.exportc: "ExtObject"} = object
  37. case kind: MyKind
  38. of M1: a:int
  39. of M2: b:float
  40. of M3: c:cstring
  41. MyObjectRef {.exportc: "ExtObject2"} = ref object
  42. case kind: MyKind
  43. of M1: a:int
  44. of M2: b:float
  45. of M3: c:cstring
  46. Helper* {.exportc: "PublicHelper".} = object
  47. case isKind: bool
  48. of true:
  49. formatted: string
  50. of false:
  51. parsed1: string
  52. parsed2: string
  53. proc newMyObject(kind: MyKind, val: string): MyObject =
  54. result = MyObject(kind: kind)
  55. case kind
  56. of M1: result.a = parseInt(val)
  57. of M2: result.b = parseFloat(val)
  58. of M3: result.c = val
  59. proc newMyObjectRef(kind: MyKind, val: string): MyObjectRef =
  60. result = MyObjectRef(kind: kind)
  61. case kind
  62. of M1: result.a = parseInt(val)
  63. of M2: result.b = parseFloat(val)
  64. of M3: result.c = val
  65. echo newMyObject(M1, "2").kind, " ", newMyObjectRef(M2, "3").kind
  66. proc test(c: Helper): string =
  67. c.formatted
  68. echo test(Helper(isKind: true, formatted: "ok"))