toyboot4e / ac-library-hs

[WIP] Haskell port of ac-library.
Creative Commons Zero v1.0 Universal
4 stars 0 forks source link

Forbidding negative size to constructors #18

Closed toyboot4e closed 1 month ago

toyboot4e commented 1 month ago

In C++, std::vector constructor takes unsigned integer, where negative integers overflow. It leads to runtime error and negative size to constructors are surely invalid.

In our vector, however, they die at negative sizes on new, but not on replicate:

replicate :: (PrimMonad m, MVector v a) => Int -> a -> m (v (PrimState m) a)
{-# INLINE replicate #-}
replicate n x = stToPrim $ basicUnsafeReplicate (delay_inline max 0 n) x

Should we emit error when given negative size to constructors?

toyboot4e commented 1 month ago

I'll do, as ac-library-hs tries to reproduce ac-library behavior in details at API level.