summary refs log tree commit diff stats
path: root/tests/run/globalaux.nim
blob: 5f6f727210e0a50f97738d7c32a169e5d035826c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
type 
  TObj*[T] = object
    val*: T

var
  totalGlobals* = 0

proc makeObj[T](x: T): TObj[T] =
  totalGlobals += 1
  result.val = x

proc globalInstance*[T]: var TObj[T] =
  var g {.global.} = when T is int: makeObj(10) else: makeObj("hello")
  result = g