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 ] =
@@ -384,7 +385,6 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
384
385
var defs = newStmtList ()
385
386
var decls = newStmtList ()
386
387
template addMeth (def: NimNode ) = defs.add def
387
- #[ return type 'auto' cannot be used in forward declarations
388
388
template addMethWithDecl (def: NimNode ) =
389
389
defs.add def
390
390
var decl = def.copyNimNode
@@ -393,7 +393,6 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
393
393
decl.add def[i].copyNimTree
394
394
decl.add newEmptyNode ()
395
395
decls.add decl
396
- ]#
397
396
var noNew = true
398
397
var
399
398
initArgs: seq [NimNode ]
@@ -449,7 +448,7 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
449
448
args[1 ]
450
449
args[1 ][1 ] = classId
451
450
if isConstructor:
452
- if args[0 ].strVal in [ " None " , " auto" ] :
451
+ if args[0 ].eqIdent " auto" :
453
452
args[0 ] = newEmptyNode ()
454
453
expectIdent args[1 ][0 ], " self"
455
454
markSelfType
@@ -463,6 +462,9 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
463
462
else :
464
463
if args.len > 1 and args[1 ][0 ].eqIdent " self" :
465
464
markSelfType
465
+ if args[0 ].eqIdent " None" :
466
+ args[0 ] = getNoneTypeNode ()
467
+ pragmas.add ident " discardable"
466
468
# Function body
467
469
var docNode: NimNode
468
470
var parsedbody = recReplaceSuperCall (
@@ -488,7 +490,11 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
488
490
newMethProc (topLevel, procName, generics_cpy, args, body,
489
491
procType, pragmas= pragmas)
490
492
)
491
- addMeth nDef
493
+ if args[0 ].eqIdent " auto" :
494
+ # return type 'auto' cannot be used in forward declarations
495
+ addMeth nDef
496
+ else :
497
+ addMethWithDecl nDef
492
498
493
499
of nnkStrLit, nnkRStrLit, nnkTripleStrLit:
494
500
result .add newCommentStmtNode $ def
@@ -498,7 +504,7 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
498
504
else :
499
505
result .add def # AS-IS
500
506
501
- addMeth genNewCls (topLevel, ident (" new" & classId.strVal), classId, initGenerics, initArgs, initPragmas)
507
+ addMethWithDecl genNewCls (topLevel, ident (" new" & classId.strVal), classId, initGenerics, initArgs, initPragmas)
502
508
503
509
let ty = nnkRefTy.newTree nnkObjectTy.newTree (emptyn, supClsNode, typDefLs)
504
510
let typDef = nnkTypeSection.newTree nnkTypeDef.newTree (classId.exportIfTop, generics, ty)
0 commit comments