File: tbracketinstantiation.nim

package info (click to toggle)
nim 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,911,644 kB
  • sloc: sh: 24,603; ansic: 1,761; python: 1,492; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (86 lines) | stat: -rw-r--r-- 2,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
discard """
  nimout: '''
type
  Bob = object
type
  Another = object
'''
"""

block: # issue #22645
  type
    Opt[T] = object
    FutureBase = ref object of RootObj
    Future[T] = ref object of FutureBase ## Typed future.
      internalValue: T ## Stored value
  template err[T](E: type Opt[T]): E = E()
  proc works(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
    var chronosInternalRetFuture: FutureBase
    template result(): untyped {.used.} =
      Future[Opt[int]](chronosInternalRetFuture).internalValue
    result = err(type(result))
  proc breaks(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
    var chronosInternalRetFuture: FutureBase
    template result(): untyped {.used.} =
      cast[Future[Opt[int]]](chronosInternalRetFuture).internalValue
    result = err(type(result))

import macros

block: # issue #16118
  macro thing(name: static[string]) =
    result = newStmtList(
      nnkTypeSection.newTree(
        nnkTypeDef.newTree(
          ident(name),
          newEmptyNode(),
          nnkObjectTy.newTree(
            newEmptyNode(),
            newEmptyNode(),
            nnkRecList.newTree()))))
  template foo(name: string): untyped =
    thing(name)
  expandMacros:
    foo("Bob")
  block:
    expandMacros:
      foo("Another")

block: # issue #19670
  type
    Past[Z] = object
    OpenObject = object

  macro rewriter(prc: untyped): untyped =
    prc.body.add(nnkCall.newTree(
      prc.params[0]
    ))
    prc
    
  macro macroAsync(name, restype: untyped): untyped =
    quote do:
      proc `name`(): Past[seq[`restype`]] {.rewriter.} = discard
      
  macroAsync(testMacro, OpenObject)

import asyncdispatch

block: # issue #11838 long
  type
    R[P] = object
      updates: seq[P]
    D[T, P] = ref object
      ps: seq[P]
      t: T
  proc newD[T, P](ps: seq[P], t: T): D[T, P] =
    D[T, P](ps: ps, t: t)
  proc loop[T, P](d: D[T, P]) =
    var results = newSeq[Future[R[P]]](10)
  let d = newD[string, int](@[1], "")
  d.loop()

block: # issue #11838 minimal
  type R[T] = object
  proc loop[T]() =
    discard newSeq[R[R[T]]]()
  loop[int]()