mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-07 16:23:07 +00:00
Better compilation error when calling without with wrong parameter
This commit is contained in:
parent
1569ef4526
commit
086fd4a8db
@ -2,13 +2,14 @@ import std/macros
|
|||||||
import ./without
|
import ./without
|
||||||
import ./private/binderror
|
import ./private/binderror
|
||||||
|
|
||||||
|
const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice}
|
||||||
|
const identKinds = {nnkIdent} + symbolKinds
|
||||||
|
|
||||||
proc undoSymbolResolution(expression, ident: NimNode): NimNode =
|
proc undoSymbolResolution(expression, ident: NimNode): NimNode =
|
||||||
## Finds symbols in the expression that match the `ident` and replaces them
|
## Finds symbols in the expression that match the `ident` and replaces them
|
||||||
## with `ident`, effectively undoing any symbol resolution that happened
|
## with `ident`, effectively undoing any symbol resolution that happened
|
||||||
## before.
|
## before.
|
||||||
|
|
||||||
const symbolKinds = {nnkSym, nnkOpenSymChoice, nnkClosedSymChoice}
|
|
||||||
|
|
||||||
if expression.kind in symbolKinds and eqIdent($expression, $ident):
|
if expression.kind in symbolKinds and eqIdent($expression, $ident):
|
||||||
return 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.
|
## Used to place guards that ensure that a Result contains a value.
|
||||||
## Exposes error when Result does not contain 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
|
let errorIdent = ident $errorname
|
||||||
|
|
||||||
# Nim's early symbol resolution might have picked up a symbol with the
|
# Nim's early symbol resolution might have picked up a symbol with the
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user