tcodegenbug1.nim 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. discard """
  2. output: '''obj = (inner: (kind: Just, id: 7))
  3. obj.inner.id = 7
  4. id = 7
  5. obj = (inner: (kind: Just, id: 7))
  6. 2'''
  7. """
  8. # bug #6960
  9. import sugar
  10. type
  11. Kind = enum None, Just, Huge
  12. Inner = object
  13. case kind: Kind
  14. of None: discard
  15. of Just: id: int
  16. of Huge: a,b,c,d,e,f: string
  17. Outer = object
  18. inner: Inner
  19. proc shouldDoNothing(id: int): Inner =
  20. dump id
  21. Inner(kind: Just, id: id)
  22. var obj = Outer(inner: Inner(kind: Just, id: 7))
  23. dump obj
  24. dump obj.inner.id
  25. obj.inner = shouldDoNothing(obj.inner.id)
  26. dump obj
  27. import os
  28. type
  29. TStatusEnum* = enum
  30. sUnknown = -1, sBuildFailure, sBuildInProgress, sBuildSuccess,
  31. sTestFailure, sTestInProgress, sTestSuccess, # ORDER MATTERS!
  32. sDocGenFailure, sDocGenInProgress, sDocGenSuccess,
  33. sCSrcGenFailure, sCSrcGenInProgress, sCSrcGenSuccess
  34. TStatus* = object
  35. status*: TStatusEnum
  36. desc*: string
  37. hash*: string
  38. proc initStatus*(): TStatus =
  39. result.status = sUnknown
  40. result.desc = ""
  41. result.hash = ""
  42. proc isInProgress*(status: TStatusEnum): bool =
  43. return status in {sBuildInProgress, sTestInProgress, sDocGenInProgress,
  44. sCSrcGenInProgress}
  45. proc `$`*(status: TStatusEnum): string =
  46. case status
  47. of sBuildFailure:
  48. return "build failure"
  49. of sBuildInProgress:
  50. return "build in progress"
  51. of sBuildSuccess:
  52. return "build finished"
  53. of sTestFailure:
  54. return "testing failure"
  55. of sTestInProgress:
  56. return "testing in progress"
  57. of sTestSuccess:
  58. return "testing finished"
  59. of sDocGenFailure:
  60. return "documentation generation failed"
  61. of sDocGenInProgress:
  62. return "generating documentation"
  63. of sDocGenSuccess:
  64. return "documentation generation succeeded"
  65. of sCSrcGenFailure:
  66. return "csource generation failed"
  67. of sCSrcGenInProgress:
  68. return "csource generation in progress"
  69. of sCSrcGenSuccess:
  70. return "csource generation succeeded"
  71. of sUnknown:
  72. return "unknown"
  73. proc makeCommitPath*(platform, hash: string): string =
  74. return platform / "nim_" & hash.substr(0, 11) # 11 Chars.
  75. type
  76. TFlag = enum
  77. A, B, C, D
  78. TFlags = set[TFlag]
  79. TObj = object
  80. x: int
  81. flags: TFlags
  82. # have a proc taking TFlags as param and returning object having TFlags field
  83. proc foo(flags: TFlags): TObj = nil
  84. # bug #5137
  85. type
  86. MyInt {.importc: "int".} = object
  87. MyIntDistinct = distinct MyInt
  88. proc bug5137(d: MyIntDistinct) =
  89. discard d.MyInt
  90. #-------------------------------------
  91. # bug #8979
  92. type
  93. MyKind = enum
  94. Fixed, Float
  95. MyObject = object
  96. someInt: int
  97. case kind: MyKind
  98. of Float: index: string
  99. of Fixed: nil
  100. MyResult = object
  101. val: array[0..1, string]
  102. vis: set[0..1]
  103. import macros
  104. func myfunc(obj: MyObject): MyResult {.raises: [].} =
  105. template index: auto =
  106. case obj.kind:
  107. of Float: $obj.index
  108. of Fixed: "Fixed"
  109. macro to_str(a: untyped): string =
  110. result = newStrLitNode(a.repr)
  111. result.val[0] = index
  112. result.val[1] = to_str(obj.kind + Ola)
  113. let x = MyObject(someInt: 10, kind: Fixed)
  114. echo myfunc(x).val.len