ttuples_issues.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. discard """
  2. output: '''
  3. '''
  4. """
  5. import tables
  6. block t4479:
  7. type
  8. MyTuple = tuple
  9. num: int
  10. strings: seq[string]
  11. ints: seq[int]
  12. var foo = MyTuple((
  13. num: 7,
  14. strings: @[],
  15. ints: @[],
  16. ))
  17. var bar = (
  18. num: 7,
  19. strings: @[],
  20. ints: @[],
  21. ).MyTuple
  22. var fooUnnamed = MyTuple((7, @[], @[]))
  23. var n = 7
  24. var fooSym = MyTuple((num: n, strings: @[], ints: @[]))
  25. block t1910:
  26. var p = newOrderedTable[tuple[a:int], int]()
  27. var q = newOrderedTable[tuple[x:int], int]()
  28. for key in p.keys:
  29. echo key.a
  30. for key in q.keys:
  31. echo key.x
  32. block t2121:
  33. type
  34. Item[K,V] = tuple
  35. key: K
  36. value: V
  37. var q = newseq[Item[int,int]](1)
  38. let (x,y) = q[0]
  39. block t2369:
  40. type HashedElem[T] = tuple[num: int, storedVal: ref T]
  41. proc append[T](tab: var seq[HashedElem[T]], n: int, val: ref T) =
  42. #tab.add((num: n, storedVal: val))
  43. var he: HashedElem[T] = (num: n, storedVal: val)
  44. #tab.add(he)
  45. var g: seq[HashedElem[int]] = @[]
  46. proc foo() =
  47. var x: ref int
  48. new(x)
  49. x[] = 77
  50. g.append(44, x)
  51. block t1986:
  52. proc test(): int64 =
  53. return 0xdeadbeef.int64
  54. const items = [
  55. (var1: test(), var2: 100'u32),
  56. (var1: test(), var2: 192'u32)
  57. ]