Skip to content

Commit

Permalink
make equals cast no side effect
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 6, 2023
1 parent 9507990 commit 7812e5c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/skinsuit/equals.nim
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ proc equalsProc(typeName, objectNode: NimNode, doExport, ptrLike: bool): NimNode
ws.add(branch)
sl.add(ws)
else: discard
let equalsBody = newStmtList()
var equalsBody = newStmtList()
if ptrLike:
let same = bindSym"same"
equalsBody.add quote do:
Expand All @@ -60,6 +60,15 @@ proc equalsProc(typeName, objectNode: NimNode, doExport, ptrLike: bool): NimNode
for r in objectNode[^1]:
generateEquals(equalsBody, r)
equalsBody.add(newTree(nnkReturnStmt, ident"true"))
let noSideEffectPragma =
when (NimMajor, NimMinor) >= (1, 6):
newTree(nnkCast, newEmptyNode(), ident"noSideEffect")
else:
ident"noSideEffect"
equalsBody = newStmtList(
newTree(nnkPragmaBlock,
newTree(nnkPragma, noSideEffectPragma),
equalsBody))
newProc(
name = ident"==".exportIf(doExport),
params = [ident"bool", newTree(nnkIdentDefs, ident"a", ident"b", typeName, newEmptyNode())],
Expand Down

0 comments on commit 7812e5c

Please sign in to comment.