Skip to content

Commit

Permalink
account for nim bug in generating equals case stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 6, 2023
1 parent 7d8cac9 commit ecdad2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion skinsuit.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.2.2"
version = "0.2.3"
author = "metagn"
description = "utility macros mostly for object variants"
license = "MIT"
Expand Down
9 changes: 9 additions & 0 deletions src/skinsuit/equals.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ proc equalsProc(typeName, objectNode: NimNode, doExport, ptrLike: bool): NimNode
if a.`kf` != b.`kf`:
return false
let cs = newTree(nnkCaseStmt, newDotExpr(ident"a", kf))
var needsEmptyElse = false
for b in field[1 .. ^1]:
let branch = copy b
for i in 0 ..< b.len - 1:
if branch[i].kind == nnkRange or
(branch[i].kind == nnkInfix and branch[i][0].eqIdent".."):
# https://github.com/nim-lang/Nim/issues/22661
# if the issue is fixed, this block needs to be disabled
needsEmptyElse = true
branch[^1] = newStmtList()
for r in b[^1]:
generateEquals(branch[^1], r)
if branch[^1].len == 0:
branch[^1].add(newTree(nnkDiscardStmt, newEmptyNode()))
cs.add(branch)
if needsEmptyElse:
cs.add(newTree(nnkElse, newTree(nnkDiscardStmt, newEmptyNode())))
sl.add(cs)
of nnkRecWhen:
let ws = newTree(nnkWhenStmt)
Expand Down

0 comments on commit ecdad2a

Please sign in to comment.