[GHC] #14237: -Wredundant-constraints incorrectly warns about required type equality constraints in default signatures

#14237: -Wredundant-constraints incorrectly warns about required type equality constraints in default signatures -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | error/warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHC emits a warning about the following function: {{{#!hs f :: (Integer ~ a) => a -> Integer f = (+ 1) }}} {{{ /private/tmp/redundant-default- constraint/src/RedundantDefaultConstraints.hs:14:1: warning: [-Wredundant- constraints] • Redundant constraint: Integer ~ a • In the type signature for: f :: forall a. Integer ~ a => a -> Integer | 14 | f :: Integer ~ a => a -> Integer | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ }}} This is understandable (though the error message could perhaps be better) because the equality is pointless. It would be better to just rewrite the type signature as `Integer -> Integer`. However, this becomes problematic when combined with `DefaultSignatures`. GHC ''also'' emits a warning for the following program: {{{#!hs class Monad m => MonadFoo m where foo :: m () default foo :: (MonadFoo m', MonadTrans t, m ~ t m') => m () foo = lift foo }}} {{{ /private/tmp/redundant-default- constraint/src/RedundantDefaultConstraints.hs:8:18: warning: [-Wredundant- constraints] • Redundant constraint: m ~ t m' • In the type signature for: foo :: forall (m' :: * -> *) (t :: (* -> *) -> * -> *). (MonadFoo m', MonadTrans t, m ~ t m') => m () | 8 | default foo :: (MonadFoo m', MonadTrans t, m ~ t m') => m () | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ }}} This is wrong, because the constraint here is necessary. The type equality cannot be “inlined” into the type, since #12918 made that illegal. The constraint cannot be removed entirely, since then the program would fail to typecheck. Therefore, GHC should not produce an error in this case. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly warns about required type equality constraints in default signatures -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by lexi.lambda): This actually seems worse than I thought—GHC warns even when type equalities are clearly required. It seems like perhaps `-Wredundant- constraints` in GHC 8.2.1 treats all type equalities as redundant? For example, this program produces a warning: {{{#!hs import GHC.Exts (IsList(..)) nums :: (Num a, IsList t, Item t ~ a) => t nums = fromList [1, 2, 3] }}} {{{ /private/tmp/redundant-default- constraint/src/RedundantDefaultConstraints.hs:9:1: warning: [-Wredundant- constraints] • Redundant constraint: Item t ~ a • In the type signature for: nums :: forall a t. (Num a, IsList t, Item t ~ a) => t | 9 | nums :: (Num a, IsList t, Item t ~ a) => t | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as redundant -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as redundant -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #12700 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #12700 Comment: Yes, this is a known pain point of `-Wredundant-constraints`. See also the very similar ticket #12700. (Among other reasons, this is why `-Wredundant-constraints` is no longer a part of `-Wall`.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as redundant -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #12700 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by lexi.lambda): I disagree that this is “very similar” to #12700. This is a **regression** from GHC 8.0, which did not have this problem. The type equality in the example given in #12700 is arguably redundant, since the program would compile without it, but the examples I’ve given in this ticket will fail to compile if the equalities are removed. When compiling these with `-Wredundant-constraints` in GHC 8.0.2, no warning is produced. In GHC 8.2.1, a warning ''is'' produced. I’m not sure why this happens, but it seems like a real step backwards, and it’s much more severe than #12700. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as
redundant
-------------------------------------+-------------------------------------
Reporter: lexi.lambda | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
error/warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: #12700 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as redundant -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: merge Priority: normal | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #12700 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => merge * milestone: => 8.2.2 Comment: Thanks for reporting this. It was an outright bug, but easy to fix. Merge to 8.2 if poss. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14237: -Wredundant-constraints incorrectly treats all type equality constraints as redundant -------------------------------------+------------------------------------- Reporter: lexi.lambda | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.2.2 Component: Compiler | Version: 8.2.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple error/warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #12700 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-8.2` as 776a660a66404408a36b92cb84397815d283b6a5. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14237#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC