results: work around void member codegen issue (#150)

This commit is contained in:
Jacek Sieka 2022-11-11 14:26:59 +01:00 committed by GitHub
parent 989047dd76
commit 8a1b6ab4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 5 deletions

View File

@ -304,11 +304,35 @@ type
## https://github.com/nim-lang/Nim/issues/13879 - double-zero-init slow
## https://github.com/nim-lang/Nim/issues/14318 - generic error raises pragma
case o: bool
of false:
e: E
of true:
v: T
# TODO https://github.com/nim-lang/Nim/issues/20699
# case o: bool
# of false:
# e: E
# of true:
# v: T
when T is void:
when E is void:
o: bool
else:
case o: bool
of false:
e: E
of true:
discard
else:
when E is void:
case o: bool
of false:
discard
of true:
v: T
else:
case o: bool
of false:
e: E
of true:
v: T
Opt*[T] = Result[T, void]

View File

@ -403,3 +403,15 @@ block: # Experiments
counter2 += 1
doAssert counter2 == 1, "one-item collection when set"
block: # Constants
# TODO https://github.com/nim-lang/Nim/issues/20699
type
WithOpt = object
opt: Opt[int]
const
noneWithOpt =
WithOpt(opt: Opt.none(int))
proc checkIt(v: WithOpt) =
doAssert v.opt.isNone()
checkIt(noneWithOpt)