Skip to content

Commit

Permalink
fix deprecated example (nim-lang#18721)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Aug 21, 2021
1 parent f0c6593 commit 5b26f2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
16 changes: 12 additions & 4 deletions doc/astspec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
22 changes: 15 additions & 7 deletions tests/astspec/tastspec.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -914,6 +923,7 @@ static:
ident"T"
),
nnkEmpty()
)
)
)
)
Expand All @@ -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:
Expand Down

0 comments on commit 5b26f2b

Please sign in to comment.