tdecls.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. targets: "c cpp js"
  4. """
  5. import std/assertions
  6. import std/decls
  7. template fun() =
  8. var s = @[10,11,12]
  9. var a {.byaddr.} = s[0]
  10. a+=100
  11. doAssert s == @[110,11,12]
  12. doAssert a is int
  13. var b {.byaddr.}: int = s[0]
  14. doAssert a.addr == b.addr
  15. {.push warningAsError[ImplicitTemplateRedefinition]: on.}
  16. # in the future ImplicitTemplateRedefinition will be an error anyway
  17. doAssert not compiles(block:
  18. # redeclaration not allowed
  19. var foo = 0
  20. var foo {.byaddr.} = s[0])
  21. doAssert not compiles(block:
  22. # ditto
  23. var foo {.byaddr.} = s[0]
  24. var foo {.byaddr.} = s[0])
  25. {.pop.}
  26. block:
  27. var b {.byaddr.} = s[1] # redeclaration ok in sub scope
  28. b = 123
  29. doAssert s == @[110,123,12]
  30. b = b * 10
  31. doAssert s == @[1100,123,12]
  32. doAssert not compiles(block:
  33. var b2 {.byaddr.}: float = s[2])
  34. doAssert compiles(block:
  35. var b2 {.byaddr.}: int = s[2])
  36. proc fun2() = fun()
  37. fun()
  38. fun2()
  39. static: fun2()
  40. when false: # pending bug #13887
  41. static: fun()