Skip to content

Commit f6c2824

Browse files
committed
fix(sugar): generic class rewrite was wrong; class O(a.c)/O(a[t]) not compile
1 parent 1927cef commit f6c2824

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/pylib/pysugar/stmt/class.nim

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,25 @@ so if wantting the attr inherited from SupCls, just write it as-is (e.g. `self.a
243243
if obj.kind != nnkIdent:
244244
# class O([SupCls])
245245
if obj.kind == nnkCall:
246-
let first = obj[1]
247-
case first.kind
248-
of nnkBracketExpr:
249-
parseGenerics first
250-
of nnkIdent, nnkObjectTy:
251-
# class O(...)
252-
classId = obj[0]
246+
if obj[0].kind == nnkBracketExpr:
247+
parseGenerics obj[0]
253248
else:
254-
error "metaclass/object.__init_subclass__ is not implemented yet, " &
255-
"only one positional param is allowed for class, got " &
256-
$obj.kind, first
249+
let arg = obj[1]
250+
case arg.kind
251+
of nnkIdent, nnkObjectTy, nnkDotExpr, nnkBracketExpr:
252+
# class O(...)
253+
classId = obj[0]
254+
else:
255+
error "metaclass/object.__init_subclass__ is not implemented yet, " &
256+
"only one positional param is allowed for class, got " &
257+
$obj.kind & " whose 1st node kind is " & $arg.kind, arg
257258
let supLen = obj.len - 1
258259
if supLen > 1:
259260
error "multi-inhert is not allowed in Nim, " &
260261
"i.e. only one super class is expected, got " & $supLen
261262
elif supLen == 1:
262263
# class O(SupCls)
263-
supCls = first
264+
supCls = obj[1]
264265
if supCls.kind != nnkObjectTy: # not `class O(object)`
265266
supClsNode = nnkOfInherit.newTree supCls
266267
defPragmas.remove1 ident"base"

0 commit comments

Comments
 (0)