summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <xzsflywind@gmail.com>2021-08-21 14:22:00 +0800
committerGitHub <noreply@github.com>2021-08-21 08:22:00 +0200
commit5b26f2bd81d6fc7d48befbfb4fa3317f713af787 (patch)
tree02dfbfdc1c49e7d6d7dbd2809a95219b274f6601
parentf0c6593412c117c7f8e19421016303416d6b8bd3 (diff)
downloadNim-5b26f2bd81d6fc7d48befbfb4fa3317f713af787.tar.gz
fix deprecated example (#18721)
-rw-r--r--doc/astspec.txt16
-rw-r--r--tests/astspec/tastspec.nim22
2 files changed, 27 insertions, 11 deletions
diff --git a/doc/astspec.txt b/doc/astspec.txt
index 6d44f7f7e..6d3fa1f8c 100644
--- a/doc/astspec.txt
+++ b/doc/astspec.txt
@@ -1082,7 +1082,7 @@ its entirety to see some of the complexities.
 Concrete syntax:
 
 .. code-block:: nim
-  type Obj[T] = object {.inheritable.}
+  type Obj[T] {.inheritable.} = object
     name: string
     case isFat: bool
     of true:
@@ -1094,10 +1094,18 @@ AST:
 
 .. code-block:: nim
   # ...
+  nnkPragmaExpr(
+    nnkIdent("Obj"),
+    nnkPragma(nnkIdent("inheritable"))
+  ),
+  nnkGenericParams(
+  nnkIdentDefs(
+    nnkIdent("T"),
+    nnkEmpty(),
+    nnkEmpty())
+  ),
   nnkObjectTy(
-    nnkPragma(
-      nnkIdent("inheritable")
-    ),
+    nnkEmpty(),
     nnkEmpty(),
     nnkRecList( # list of object parameters
       nnkIdentDefs(
diff --git a/tests/astspec/tastspec.nim b/tests/astspec/tastspec.nim
index 33a245b1b..c99d8ec79 100644
--- a/tests/astspec/tastspec.nim
+++ b/tests/astspec/tastspec.nim
@@ -871,11 +871,20 @@ static:
 
   scope:
     macro testRecCase(ast: untyped): untyped =
-      ast.peelOff({nnkStmtList, nnkTypeSection})[2].matchAst:
-      of nnkObjectTy(
-        nnkPragma(
-          ident"inheritable"
+      ast.peelOff({nnkStmtList, nnkTypeSection}).matchAst:
+      of nnkTypeDef(
+        nnkPragmaExpr(
+          ident"Obj",
+          nnkPragma(ident"inheritable")
         ),
+        nnkGenericParams(
+        nnkIdentDefs(
+          ident"T",
+          nnkEmpty(),
+          nnkEmpty())
+        ),
+        nnkObjectTy(
+        nnkEmpty(),
         nnkEmpty(),
         nnkRecList( # list of object parameters
           nnkIdentDefs(
@@ -914,6 +923,7 @@ static:
                     ident"T"
                   ),
                   nnkEmpty()
+                  )
                 )
               )
             )
@@ -922,10 +932,8 @@ static:
       ):
         echo "ok"
 
-
-
     testRecCase:
-      type Obj[T] = object {.inheritable.}
+      type Obj[T] {.inheritable.} = object
         name: string
         case isFat: bool
         of true: