input-output-hk / io-sim

Haskell's IO simulator which closely follows core packages (base, async, stm).
https://hackage.haskell.org/package/io-sim
Apache License 2.0
37 stars 15 forks source link

Control.Monad.IOSim.STM.isEmptyTBQueueDefault #43

Closed sdzx-1 closed 1 year ago

sdzx-1 commented 1 year ago

Describe the bug

The implementation of Control.Monad.IOSim.STM.isEmptyTBQueueDefault is wrong.

https://github.com/input-output-hk/io-sim/blob/0df93fe773e9b66ce35f3637128533e5b0029558/io-sim/src/Control/Monad/IOSim/STM.hs#L172

Additional context

-- wrong
isEmptyTBQueueDefault :: MonadSTM m => TBQueueDefault m a -> STM m Bool
isEmptyTBQueueDefault (TBQueue queue _size) = do
  (xs, _, _, _) <- readTVar queue
  case xs of
    _:_ -> return False
    []  -> return True
----------------------------------------

-- right
isEmptyTBQueueDefault :: MonadSTM m => TBQueueDefault m a -> STM m Bool
isEmptyTBQueueDefault (TBQueue queue _size) = do
  (xs, _, ys, _) <- readTVar queue
  case xs of
    (_:_) -> return False
    [] -> case ys of
               [] -> return True
               _  -> return False

pr: https://github.com/input-output-hk/io-sim/pull/44 @coot

coot commented 1 year ago

Good catch, thanks for your PR as well.