Skip to content

`deriving newtype Integral` for Integer newtypes invokes `Widentities` in ghc-9

Summary

Attempting to derive a newtype Integral instance for a newtype that wraps an Integer produces a -Widentitites warning.

Steps to reproduce

Starting from a Test.hs:

{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Test where

newtype I = I Integer
  deriving newtype (Enum, Num, Eq, Ord, Real, Integral)

and running e.g. stack ghc Test.hs --ghc-options "-Werror=identities" (given a stack.yaml targeted at a ghc-9.0.2 or ghc-9.2.2) results in:

GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Test             ( /home/mrkun/serokell/ghc-test/Test.hs, interpreted )

/home/mrkun/serokell/ghc-test/Test.hs:7:47: error: [-Widentities, -Werror=identities]
    Call of toInteger :: Integer -> Integer
      can probably be omitted
  |
7 |   deriving newtype (Enum, Num, Eq, Ord, Real, Integral)
  |                                               ^^^^^^^^
Failed, no modules loaded.

Expected behavior

No errors or warnings reported; e.g. same setup but with a ghc-8.10.7 produces:

GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Test             ( /home/mrkun/serokell/ghc-test/Test.hs, interpreted )
Ok, one module loaded.

Environment

  • GHC version used: 9.0.2; 9.2.2

  • Operating System: Linux (Ubuntu 18.04.1)

  • System Architecture: x86_64

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information