2
2
import std/ macros
3
3
import ./ frame, ./ funcSignature, ./ decorator, ./ types
4
4
import ./ pydef
5
-
5
+ import ../../ noneType
6
+ proc getNoneTypeNode : NimNode = bindSym " NoneType"
6
7
template emptyn : NimNode = newEmptyNode ()
7
8
8
9
proc parseDeclWithType (def: NimNode ): tuple [name, typ, val: NimNode ] =
@@ -377,7 +378,6 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
377
378
var defs = newStmtList ()
378
379
var decls = newStmtList ()
379
380
template addMeth (def: NimNode ) = defs.add def
380
- #[ return type 'auto' cannot be used in forward declarations
381
381
template addMethWithDecl (def: NimNode ) =
382
382
defs.add def
383
383
var decl = def.copyNimNode
@@ -386,7 +386,6 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
386
386
decl.add def[i].copyNimTree
387
387
decl.add newEmptyNode ()
388
388
decls.add decl
389
- ]#
390
389
var noNew = true
391
390
var
392
391
initArgs: seq [NimNode ]
@@ -441,7 +440,7 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
441
440
args[1 ]
442
441
args[1 ][1 ] = classId
443
442
if isConstructor:
444
- if args[0 ].strVal in [ " None " , " auto" ] :
443
+ if args[0 ].eqIdent " auto" :
445
444
args[0 ] = newEmptyNode ()
446
445
expectIdent args[1 ][0 ], " self"
447
446
markSelfType
@@ -455,6 +454,9 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
455
454
else :
456
455
if args.len > 1 and args[1 ][0 ].eqIdent " self" :
457
456
markSelfType
457
+ if args[0 ].eqIdent " None" :
458
+ args[0 ] = getNoneTypeNode ()
459
+ pragmas.add ident " discardable"
458
460
# Function body
459
461
var docNode: NimNode
460
462
var parsedbody = recReplaceSuperCall (
@@ -479,7 +481,11 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
479
481
newMethProc (topLevel, procName, generics_cpy, args, body,
480
482
procType, pragmas= pragmas)
481
483
)
482
- addMeth nDef
484
+ if args[0 ].eqIdent " auto" :
485
+ # return type 'auto' cannot be used in forward declarations
486
+ addMeth nDef
487
+ else :
488
+ addMethWithDecl nDef
483
489
484
490
of nnkStrLit, nnkRStrLit, nnkTripleStrLit:
485
491
result .add newCommentStmtNode $ def
@@ -489,7 +495,7 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
489
495
else :
490
496
result .add def # AS-IS
491
497
492
- addMeth genNewCls (ident (" new" & classId.strVal).exportIfTop, classId, generics, initArgs, initPragmas)
498
+ addMethWithDecl genNewCls (ident (" new" & classId.strVal).exportIfTop, classId, generics, initArgs, initPragmas)
493
499
494
500
let ty = nnkRefTy.newTree nnkObjectTy.newTree (emptyn, supClsNode, typDefLs)
495
501
let typDef = nnkTypeSection.newTree nnkTypeDef.newTree (classId.exportIfTop, generics, ty)
0 commit comments