Skip to content

Compiler hangs on negative literal

As observed in #24797 (comment 564128), the following program hangs the compiler:

{-# LANGUAGE RequiredTypeArguments #-}
{-# LANGUAGE NegativeLiterals #-}

module T26861 where

import Data.Data
import GHC.TypeLits

main :: IO ()
main = print (natVis (-42))

natVis :: forall a -> KnownNat a => Integer
natVis n = natVal (Proxy @n)

Expected behavior

The compiler should report the following error message:

T26861.hs:10:23: error: [GHC-93632]
    • Illegal literal in type (type literals must not be negative): -42
    • In the type ‘-42’
      In the first argument of ‘print’, namely ‘(natVis (-42))’
      In the expression: print (natVis (-42))
   |
10 | main = print (natVis (-42))
   |                       ^^^
Edited by Vladislav Zavialov
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information