results: make `?` work with void (#50)

This commit is contained in:
Jacek Sieka 2020-07-13 18:09:45 +02:00 committed by GitHub
parent 61e0f82858
commit ec2f52b0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -621,7 +621,7 @@ template value*[E](self: var Result[void, E]) =
mixin get
self.get()
template `?`*[T, E](self: Result[T, E]): T =
template `?`*[T, E](self: Result[T, E]): auto =
## Early return - if self is an error, we will return from the current
## function, else we'll move on..
##
@ -639,4 +639,5 @@ template `?`*[T, E](self: Result[T, E]): T =
else:
return err(typeof(result), v.e)
v.v
when not(T is void):
v.v

View File

@ -256,3 +256,13 @@ except:
discard
doAssert vErr.mapErr(proc(x: int): int = 10).error() == 10
func voidF(): VoidRes =
ok()
func voidF2(): VoidRes =
? voidF()
ok()
doAssert voidF2().isOk