Skip to content

Inconsistent -Wpartial-fields warnings with (~) vs. (~~)

In this program:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wpartial-fields #-}
module Bug where

import Data.Type.Equality

data T1 z where
  MkT1a :: { rec1 :: () } -> T1 Int
  MkT1b :: (z ~ Bool) => T1 z

data T2 z where
  MkT2a :: { rec2 :: () } -> T2 Int
  MkT2b :: (z ~~ Bool) => T2 z

I get no -Wpartial-fields–related warnings for rec1, but I do for rec2:

GHCi, version 8.6.4: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:13:14: warning: [-Wpartial-fields]
    Use of partial record field selector: ‘rec2’
   |
13 |   MkT2a :: { rec2 :: () } -> T2 Int
   |              ^^^^

This feels strangely inconsistent, since if GHC doesn't warn for rec1, which uses (~), then I feel like it shouldn't warn for rec2 either, as the only difference is that the surrounding constructor uses a slightly different equality constraint (~~).

The reason this happens is because the dataConCannotMatch function has special reasoning for (~), but not (~~). Patch incoming.

Trac metadata
Trac field Value
Version 8.6.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information