From 8f5f2140c046ed7952f31a31148b6678e982da1e Mon Sep 17 00:00:00 2001 From: Smooth Operator Date: Sun, 3 Oct 2021 15:55:14 -0400 Subject: [PATCH] 2.1.2: fix another symbol hack --- badresults.nim | 12 ++++++++---- badresults.nimble | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/badresults.nim b/badresults.nim index abd87d0..be85a14 100644 --- a/badresults.nim +++ b/badresults.nim @@ -15,22 +15,26 @@ type of true: v: T +func newResultError[E](e: E; s: string): ResultError[E] {.inline, nimcall.} = + ## capturing ResultError... + ResultError[E](error: e, msg: s) + macro toException*[E](err: E): ResultError[E] = err.expectKind nnkCheckedFieldExpr # err is `self.e`, a checked field expr let e = err[0] # unwrap checked-field to get dot expr - let T = getTypeImpl e[1] # unwrap dot expr to get the error type + let re = bindSym"newResultError" quote: when compiles($`e`): - ResultError[`T`](error: `e`, msg: "Result isErr: " & $`e`) + `re`(`e`, "Result isErr: " & $`e`) else: - ResultError[`T`](error: `e`) + `re`(`e`, "Result isErr; no `$` in scope.") macro raiseResultError[T, E](self: Result[T, E]): untyped = quote: when `E` is ref Exception: if `self`.e.isNil: # for example Result.default()! - raise ResultError[void](msg: "Result isErr: (no exception)") + raise ResultError[void](msg: "Result isErr; no exception.") else: raise `self`.e else: diff --git a/badresults.nimble b/badresults.nimble index 70c4fd8..1ec2262 100644 --- a/badresults.nimble +++ b/badresults.nimble @@ -1,4 +1,4 @@ -version = "2.1.1" +version = "2.1.2" author = "disruptek" description = "a simpler and less fascist fork of nim-result" license = "MIT"