Skip to content

Commit 3f5a7ee

Browse files
Yield spine in Bit's deepErrorX
Fixes #2978
1 parent 3913be3 commit 3f5a7ee

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXED: `ensureSpine` for `Bit` now yields its data constructor instead of `XException` [#2978](https://github.com/clash-lang/clash-compiler/issues/2978)

clash-prelude/src/Clash/Sized/Internal/BitVector.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ instance ShowX Bit where
277277
showsPrecX = showsPrecXWith showsPrec
278278

279279
instance NFDataX Bit where
280-
deepErrorX = errorX
280+
deepErrorX s = unpack# (deepErrorX s)
281281
ensureSpine = unpack# . xToBV . pack#
282282
rnfX = rwhnfX
283283
hasUndefined bv = isLeft (isX bv) || unsafeMask# bv /= 0

clash-prelude/tests/Clash/Tests/BitVector.hs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import qualified Test.Tasty.QuickCheck as Q
2525

2626
import Clash.Prelude
2727
(Bit, high, low, bitPattern, type (<=), type (-), natToInteger, msb, bLit, hLit, oLit, rotateL, rotateR)
28-
import Clash.Sized.Internal.BitVector (BitVector (..))
28+
import Clash.Sized.Internal.BitVector (BitVector (..), Bit(..))
29+
import Clash.XException (ensureSpine, errorX, deepErrorX)
2930

3031
import Clash.Tests.SizedNum
3132

@@ -135,6 +136,32 @@ tests = localOption (Q.QuickCheckMaxRatio 2) $ testGroup "All"
135136
, testCase "show17" $ show @(BitVector 12) $(oLit "5324") @?= "0b1010_1101_0100"
136137
, testCase "show17" $ show @(BitVector 12) $(oLit ".324") @?= "0b...0_1101_0100"
137138
]
139+
, testGroup "NFDataX"
140+
[ testCase
141+
"ensureSpine should yield BV constructor"
142+
(case ensureSpine (errorX "" :: BitVector 2) of
143+
BV m v -> do
144+
m @?= 3
145+
v @?= 0)
146+
, testCase
147+
"deepErrorX should yield BV constructor"
148+
(case deepErrorX "" :: BitVector 2 of
149+
BV m v -> do
150+
m @?= 3
151+
v @?= 0)
152+
, testCase
153+
"ensureSpine should yield Bit constructor"
154+
(case ensureSpine (errorX "" :: Bit) of
155+
Bit m v -> do
156+
m @?= 1
157+
v @?= 0)
158+
, testCase
159+
"deepErrorX should yield Bit constructor"
160+
(case deepErrorX "" :: Bit of
161+
Bit m v -> do
162+
m @?= 1
163+
v @?= 0)
164+
]
138165
]
139166

140167
fromIntegerProp :: forall m. KnownNat m => Proxy m -> Integer -> Q.Property

0 commit comments

Comments
 (0)