Skip to content

Commit

Permalink
nimHasGenericsOpenSym already declared even though it's not working
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Aug 12, 2024
1 parent 5955e99 commit aee3e24
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions results.nim
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ const
# https://github.com/nim-lang/Nim/pull/23939

resultsGenericsOpenSymWorkaround* {.booldefine.} =
resultsGenericsOpenSym and not defined(nimHasGenericsOpenSym)
resultsGenericsOpenSym and not defined(nimHasGenericsOpenSym2)
## Prefer macro workaround to solve genericsOpenSym issue
# TODO https://github.com/nim-lang/Nim/pull/23892#discussion_r1713434311

pushGenericsOpenSym = defined(nnimHasGenericsOpenSym) and resultsGenericsOpenSym
resultsGenericsOpenSymWorkaroundHint* {.booldefine.} = true

func raiseResultOk[T, E](self: Result[T, E]) {.noreturn, noinline.} =
# noinline because raising should take as little space as possible at call
Expand Down Expand Up @@ -1057,6 +1058,8 @@ when resultsGenericsOpenSymWorkaround:
# No arguments - replace call symbol
result = copyNimNode(n)
result.add with
when resultsGenericsOpenSymWorkaroundHint:
hint("Replaced node with injected symbol " & what, n[0])
else:
# `error(...)` - replace args but not function name
result = copyNimNode(n)
Expand Down Expand Up @@ -1224,6 +1227,9 @@ when resultsGenericsOpenSymWorkaround:
def

else:
# TODO https://github.com/nim-lang/Nim/pull/23892#discussion_r1713434311
const pushGenericsOpenSym = defined(nimHasGenericsOpenSym2) and resultsGenericsOpenSym

template isOkOr*[T, E](self: Result[T, E], body: untyped) =
## Evaluate `body` iff result has been assigned an error
## `body` is evaluated lazily.
Expand All @@ -1249,7 +1255,7 @@ else:
case s.oResultPrivate
of false:
when E isnot void:
when resultsGenericsOpenSym:
when pushGenericsOpenSym:
{.push experimental: "genericsOpenSym".}
template error(): E {.used.} =
s.eResultPrivate
Expand Down Expand Up @@ -1283,7 +1289,7 @@ else:
case s.oResultPrivate
of true:
when T isnot void:
when resultsGenericsOpenSym:
when pushGenericsOpenSym:
{.push experimental: "genericsOpenSym".}
template value(): T {.used.} =
s.vResultPrivate
Expand Down Expand Up @@ -1323,7 +1329,7 @@ else:
s.vResultPrivate
of false:
when E isnot void:
when resultsGenericsOpenSym:
when pushGenericsOpenSym:
{.push experimental: "genericsOpenSym".}
template error(): E {.used.} =
s.eResultPrivate
Expand All @@ -1342,7 +1348,7 @@ else:
s.eResultPrivate
of true:
when T isnot void:
when resultsGenericsOpenSym:
when pushGenericsOpenSym:
{.push experimental: "genericsOpenSym".}
template value(): T {.used.} =
s.vResultPrivate
Expand Down

0 comments on commit aee3e24

Please sign in to comment.