serokell / universum

:milky_way: Prelude written in @Serokell
MIT License
176 stars 26 forks source link

deriving Container produce warning "Redundant constraint" #208

Closed yihuang closed 2 years ago

yihuang commented 5 years ago

Using ghc-8.6.3.

{-# LANGUAGE GeneralizedNewtypeDeriving, UndecidableInstances, FlexibleContexts, GADTs #-}
module Test where
import Universum

newtype Test = Test [Int]
    deriving (Container)

Build with stack ghc -- -fwarn-redundant-constraints %, result:

test.hs:6:15: warning: [-Wredundant-constraints]
    • Redundant constraint: Eq (Element Test)
    • In an expression type signature:
           Eq (Element Test) => Element Test -> Test -> Bool
      In the expression:
          GHC.Prim.coerce
            @(Element ([] Int) -> [] Int -> Bool)
            @(Element Test -> Test -> Bool)
            Universum.elem ::
            Eq (Element Test) => Element Test -> Test -> Bool
      In an equation for ‘Universum.elem’:
          Universum.elem
            = GHC.Prim.coerce
                @(Element ([] Int) -> [] Int -> Bool)
                @(Element Test -> Test -> Bool)
                Universum.elem ::
                Eq (Element Test) => Element Test -> Test -> Bool
      When typechecking the code for ‘Universum.elem’
        in a derived instance for ‘Container Test’:
        To see the code I am typechecking, use -ddump-deriv
  |
6 |     deriving (Container)
  |               ^^^^^^^^^
DK318 commented 2 years ago

It seems that this is a compiler bug. In ghc-9.0.2 your snippet compiles without a redundant constraint warning.