summary refs log tree commit diff stats
path: root/tests/stdlib/tdecls.nim
blob: 5cf352cfbfc4af879c55ae9c338e138b36a6a9cb (plain) (blame)
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
discard """
  targets: "c cpp js"
"""
import std/assertions
import std/decls

template fun() =
  var s = @[10,11,12]
  var a {.byaddr.} = s[0]
  a+=100
  doAssert s == @[110,11,12]
  doAssert a is int
  var b {.byaddr.}: int = s[0]
  doAssert a.addr == b.addr

  when false:
    # template specific redeclaration issue
    # see https://github.com/nim-lang/Nim/issues/8275
    doAssert not compiles(block:
      # redeclaration not allowed
      var foo = 0
      var foo {.byaddr.} = s[0])

    doAssert not compiles(block:
      # ditto
      var foo {.byaddr.} = s[0]
      var foo {.byaddr.} = s[0])

  block:
    var b {.byaddr.} = s[1] # redeclaration ok in sub scope
    b = 123

  doAssert s == @[110,123,12]

  b = b * 10
  doAssert s == @[1100,123,12]

  doAssert not compiles(block:
    var b2 {.byaddr.}: float = s[2])

  doAssert compiles(block:
    var b2 {.byaddr.}: int = s[2])

proc fun2() = fun()
fun()
fun2()
static: fun2()
when false: # pending bug #13887
  static: fun()