codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

A procedure inside "=?" sometimes called twice #23

Closed Bulat-Ziganshin closed 1 year ago

Bulat-Ziganshin commented 1 year ago

questionable version 0.10.5 (as used by Codex) and this is minimal case, compiled from the root of questionable:

import ./questionable
import ./questionable/results

type
  Block* = ref object of RootObj
    cid*: string

proc make_echo: ?!Block =
  echo "make_echo"
  Block(cid:"1").success

for i in 1..1:
  if cid =? make_echo().?cid:
    echo "outside"

its output:

make_echo
make_echo
outside

Compiled with nim c -d:danger testQ.nim

Bulat-Ziganshin commented 1 year ago

I'm on Windows and compiler is

Nim Compiler Version 1.2.16 [Windows: amd64]
Compiled at 2022-09-27
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: c6a9f27b3e36bae9aacec1bd6c37893fb98fd33f
active boot switches: -d:release
markspanbroek commented 1 year ago

Thanks for the bug report @Bulat-Ziganshin! It turned out that multiple evaluations of expressions happened in a lot of places. A fix is released in questionable 0.10.6.