codex-storage / questionable

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

Fix: ensure that options and results are only evaluated once #24

Closed markspanbroek closed 1 year ago

markspanbroek commented 1 year ago

fixes #23

markspanbroek commented 1 year ago

This fix is probably interesting for you as well @Menduist. The code in nim-quic that replaces questionable has the same problem; the optional expression is evaluated more than once.

Menduist commented 1 year ago

Thanks, will fix :)

Bulat-Ziganshin commented 1 year ago

I didn't do deeper research, but in my example, double evaluation happens only inside a loop. Are you sure that your new tests cover the problematic cases?

markspanbroek commented 1 year ago

Yes, I checked that the code from your bug report works. I'm not sure why you needed the loop to trigger the double evaluation; I got the double evaluation also without the loop.

Bulat-Ziganshin commented 1 year ago

I rechecked - you are right, the problem manifests in 0.10.5 even when I delete for from my example.