fix deprecated example (#18721)

This commit is contained in:
flywind 2021-08-21 14:22:00 +08:00 • committed by GitHub
commit 5b26f2bd81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 11 deletions

View file

@ -1082,7 +1082,7 @@ its entirety to see some of the complexities.
Concrete syntax: Concrete syntax:
.. code-block:: nim .. code-block:: nim
type Obj[T] = object {.inheritable.} type Obj[T] {.inheritable.} = object
name: string name: string
case isFat: bool case isFat: bool
of true: of true:
@ -1094,10 +1094,18 @@ AST:
.. code-block:: nim .. code-block:: nim
# ... # ...
nnkPragmaExpr(
nnkIdent("Obj"),
nnkPragma(nnkIdent("inheritable"))
),
nnkGenericParams(
nnkIdentDefs(
nnkIdent("T"),
nnkEmpty(),
nnkEmpty())
),
nnkObjectTy( nnkObjectTy(
nnkPragma( nnkEmpty(),
nnkIdent("inheritable")
),
nnkEmpty(), nnkEmpty(),
nnkRecList( # list of object parameters nnkRecList( # list of object parameters
nnkIdentDefs( nnkIdentDefs(

View file

@ -871,11 +871,20 @@ static:
scope: scope:
macro testRecCase(ast: untyped): untyped = macro testRecCase(ast: untyped): untyped =
ast.peelOff({nnkStmtList, nnkTypeSection})[2].matchAst: ast.peelOff({nnkStmtList, nnkTypeSection}).matchAst:
of nnkObjectTy( of nnkTypeDef(
nnkPragma( nnkPragmaExpr(
ident"inheritable" ident"Obj",
nnkPragma(ident"inheritable")
), ),
nnkGenericParams(
nnkIdentDefs(
ident"T",
nnkEmpty(),
nnkEmpty())
),
nnkObjectTy(
nnkEmpty(),
nnkEmpty(), nnkEmpty(),
nnkRecList( # list of object parameters nnkRecList( # list of object parameters
nnkIdentDefs( nnkIdentDefs(
@ -914,6 +923,7 @@ static:
ident"T" ident"T"
), ),
nnkEmpty() nnkEmpty()
)
) )
) )
) )
@ -922,10 +932,8 @@ static:
): ):
echo "ok" echo "ok"
testRecCase: testRecCase:
type Obj[T] = object {.inheritable.} type Obj[T] {.inheritable.} = object
name: string name: string
case isFat: bool case isFat: bool
of true: of true: