summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorcooldome <ariabushenko@gmail.com>2020-11-26 13:44:06 +0000
committerGitHub <noreply@github.com>2020-11-26 13:44:06 +0000
commit2f1a9eadd7023d6e6f837c8cb97b1cef8e599a61 (patch)
treef8820b4b9a7e82d09ca484d12e925b4ec0be82d2
parent8c12d3e29d06383f1752b24eeabcbf0439e920d5 (diff)
downloadNim-2f1a9eadd7023d6e6f837c8cb97b1cef8e599a61.tar.gz
More on #16110 (#16130)
* fix #16110

* refs #16110

* fix comment

* Trigger build

* use shallowCopy for efficiency
-rw-r--r--compiler/semstmts.nim13
-rw-r--r--tests/macros/tgetimpl.nim27
2 files changed, 32 insertions, 8 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 713867b76..d7f66208e 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1278,8 +1278,17 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
       incl st.flags, tfRefsAnonObj
       let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"),
                        nextId c.idgen, getCurrOwner(c), s.info)
-      obj.ast = a.copyTree
-      obj.ast[0] = newSymNode(obj)
+      let symNode = newSymNode(obj)
+      obj.ast = a.shallowCopy
+      case a[0].kind
+        of nkSym: obj.ast[0] = symNode
+        of nkPragmaExpr: 
+          obj.ast[0] = a[0].shallowCopy
+          obj.ast[0][0] = symNode
+          obj.ast[0][1] = a[0][1]
+        else: assert(false)
+      obj.ast[1] = a[1]
+      obj.ast[2] = a[2][0]
       if sfPure in s.flags:
         obj.flags.incl sfPure
       obj.typ = st.lastSon
diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim
index de655561b..de132f253 100644
--- a/tests/macros/tgetimpl.nim
+++ b/tests/macros/tgetimpl.nim
@@ -71,15 +71,30 @@ assert: check_gen_proc(len(a)) == (false, true)
 
 macro check(x: type): untyped =
   let z = getType(x)
-  let y = getImpl(z[1])
-  echo z.treeRepr
+  let y = getImpl(z[1])  
+  let sym = if y[0].kind == nnkSym: y[0] else: y[0][0]
   expectKind(z[1], nnkSym)
-  expectKind(y[0], nnkSym)
-  doAssert(y[0] == z[1])
+  expectKind(sym, nnkSym)
+  expectKind(y[2], nnkObjectTy)
+  doAssert(sym == z[1])
 
 type
   TirePtr = ptr object
     code: int
 
-var z: TirePtr
-check(typeof(z[]))
\ No newline at end of file
+  TireRef* = ref object
+    code: int
+
+  TireRef2* {.inheritable.} = ref object
+    code: int
+
+  TireRef3* {.inheritable.} = object
+    code: int
+
+var z1: TirePtr
+check(typeof(z1[]))
+var z2: TireRef
+check(typeof(z2[]))
+var z3: TireRef2
+check(typeof(z3[]))
+check(TireRef3)