fix results compiletime regression (#203)
* fix results compiletime regression * disable results.value compiletime test for pre 1.6 nim
This commit is contained in:
parent
8bb07fac39
commit
5c519d8582
|
@ -801,7 +801,10 @@ func value*[T, E](self: Result[T, E]): T {.inline.} =
|
|||
## See also: Option.get
|
||||
withAssertOk(self):
|
||||
when T isnot void:
|
||||
self.vResultPrivate
|
||||
# TODO: remove result usage.
|
||||
# A workaround for nim VM bug:
|
||||
# https://github.com/nim-lang/Nim/issues/22216
|
||||
result = self.vResultPrivate
|
||||
|
||||
func value*[T: not void, E](self: var Result[T, E]): var T {.inline.} =
|
||||
## Fetch value of result if set, or raise Defect
|
||||
|
|
|
@ -504,3 +504,29 @@ block: # Constants
|
|||
doAssert c == [1] and d == [2]
|
||||
let (e, f) = v.unsafeGet()
|
||||
doAssert e == [1] and f == [2]
|
||||
|
||||
block:
|
||||
# withAssertOk evaluated as statement instead of expr
|
||||
# https://github.com/nim-lang/Nim/issues/22216
|
||||
func bug(): Result[uint16, string] =
|
||||
ok(1234)
|
||||
|
||||
const
|
||||
x = bug()
|
||||
y = x.value()
|
||||
|
||||
doAssert y == 1234
|
||||
|
||||
when (NimMajor, NimMinor) >= (1,6):
|
||||
# pre 1.6 nim vm have worse bug
|
||||
static:
|
||||
var z = bug()
|
||||
z.value() = 15
|
||||
let w = z.get()
|
||||
doAssert w == 15
|
||||
|
||||
let
|
||||
xx = bug()
|
||||
yy = x.value()
|
||||
|
||||
doAssert yy == 1234
|
||||
|
|
Loading…
Reference in New Issue