clash-lang/clash-compiler

`PatError` test not actually testing `patError`

Opened this issue · 0 comments

First discovered by @leonschoorl in the GHC 9.10 upgrade PR: #2758 (comment)

it turns out that every since the GHC 9.2 series, the PatError tests is desugared to:

topEntity
  = \ (ds_d1di :: Maybe Int) ->
      case ds_d1di of {
        __DEFAULT ->
          case GHC.Internal.Control.Exception.Base.patError
                 @GHC.Types.LiftedRep   
                 @()
                 "tests/shouldwork/Basic/PatError.hs:6:1-22|function topEntity"#
          of {};
        Just x_a1cs -> x_a1cs
      }

which Clash's GHC2Core process turns into:

λ(ds :: GHC.Internal.Maybe.Maybe GHC.Types.Int) ->
case ds[LocalId] of
  GHC.Internal.Maybe.Nothing  ->
    Clash.Normalize.Primitives.undefined @GHC.Types.Int
  GHC.Internal.Maybe.Just (x :: GHC.Types.Int) ->
    x[LocalId]

Which means that the test actually no longer tests whether we can deal with patError in the intended way.

We should probably change the GHC2Core process so that it preserves "bottoming" primitives when converting empty case statements.