Skip to content

Surprising behavior with wildcard pattern and unlifted type

Summary

There is surprising behavior around wildcard pattern and evaluation of value of unlifted type.

Steps to reproduce

{-# LANGUAGE UnliftedDatatypes #-}

{-# OPTIONS_GHC -Wall #-}

module Main where

import GHC.Exts (UnliftedType)

type T :: UnliftedType
data T = T

ex1 :: ()
ex1 = let _ = undefined :: T in ()

ex2 :: ()
ex2 = let _a = undefined :: T in ()


ghci> ex1                                                                                                                         
()                                                                                                                                
ghci> ex2                                                                                                                         
*** Exception: Prelude.undefined                                                                                                  
CallStack (from HasCallStack):                                                                                                    
  undefined, called at test17.hs:53:16 in fake-package-0-inplace:Main                                                             

Expected behavior

I expect ex1 and ex2 to have the same behavior.

Environment

  • GHC version used: 9.2 and 9.4
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information