Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Tc/Gen/HsType.hs
    ... ... @@ -1264,8 +1264,10 @@ tcHsType _ rn_ty@(HsStarTy _ _) exp_kind
    1264 1264
       = checkExpKind rn_ty liftedTypeKind liftedTypeKind exp_kind
    
    1265 1265
     
    
    1266 1266
     --------- Literals
    
    1267
    -tcHsType _ rn_ty@(HsTyLit _ (HsNumTy _ n)) exp_kind
    
    1268
    -  = do { checkWiredInTyCon naturalTyCon
    
    1267
    +tcHsType _ rn_ty@(HsTyLit _ (HsNumTy x n)) exp_kind
    
    1268
    +  = do { when (n < 0) $
    
    1269
    +           addErr $ TcRnNegativeNumTypeLiteral (HsNumTy x n)
    
    1270
    +       ; checkWiredInTyCon naturalTyCon
    
    1269 1271
            ; checkExpKind rn_ty (mkNumLitTy n) naturalTy exp_kind }
    
    1270 1272
     
    
    1271 1273
     tcHsType _ rn_ty@(HsTyLit _ (HsStrTy _ s)) exp_kind
    

  • testsuite/tests/typecheck/should_fail/T26861.hs
    1
    +{-# LANGUAGE DataKinds #-}
    
    2
    +{-# LANGUAGE NegativeLiterals #-}
    
    3
    +{-# LANGUAGE RequiredTypeArguments #-}
    
    4
    +
    
    5
    +module T26861 where
    
    6
    +
    
    7
    +import Data.Proxy
    
    8
    +import GHC.TypeLits
    
    9
    +
    
    10
    +main :: IO ()
    
    11
    +main = print (natVis (-42))
    
    12
    +
    
    13
    +natVis :: forall a -> KnownNat a => Integer
    
    14
    +natVis n = natVal (Proxy @n)

  • testsuite/tests/typecheck/should_fail/T26861.stderr
    1
    +T26861.hs:11:23: error: [GHC-93632]
    
    2
    +    • Illegal literal in type (type literals must not be negative): -42
    
    3
    +    • In the type ‘-42’
    
    4
    +      In the first argument of ‘print’, namely ‘(natVis (-42))’
    
    5
    +      In the expression: print (natVis (-42))
    
    6
    +

  • testsuite/tests/typecheck/should_fail/all.T
    ... ... @@ -752,3 +752,4 @@ test('T23162a', normal, compile_fail, [''])
    752 752
     test('T23162b', normal, compile_fail, [''])
    
    753 753
     test('T23162c', normal, compile, [''])
    
    754 754
     test('T23162d', normal, compile, [''])
    
    755
    +test('T26861', normal, compile_fail, [''])