mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-02 13:53:11 +00:00
Better compilation error when calling without with wrong parameter
This commit is contained in:
parent
1569ef4526
commit
9af4ce1ca1
@ -2,13 +2,14 @@ import std/macros
|
||||
import ./without
|
||||
import ./private/binderror
|
||||
|
||||
const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice}
|
||||
const identKinds = {nnkIdent} + symbolKinds
|
||||
|
||||
proc undoSymbolResolution(expression, ident: NimNode): NimNode =
|
||||
## Finds symbols in the expression that match the `ident` and replaces them
|
||||
## with `ident`, effectively undoing any symbol resolution that happened
|
||||
## before.
|
||||
|
||||
const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice}
|
||||
|
||||
if expression.kind in symbolKinds and eqIdent($expression, $ident):
|
||||
return ident
|
||||
|
||||
@ -22,6 +23,9 @@ macro without*(condition, errorname, body: untyped): untyped =
|
||||
## Used to place guards that ensure that a Result contains a value.
|
||||
## Exposes error when Result does not contain a value.
|
||||
|
||||
if errorname.kind notin identKinds:
|
||||
error("expected an identifier, got " & errorname.repr, errorname)
|
||||
|
||||
let errorIdent = ident $errorname
|
||||
|
||||
# Nim's early symbol resolution might have picked up a symbol with the
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user