Opened 2 years ago

Closed 2 years ago

#14094 closed bug (fixed)

DeriveAnyClass doesn't warn about unimplemented type families

Reported by: RyanGlScott Owned by: RyanGlScott
Priority: normal Milestone: 8.4.1
Component: Compiler Version: 8.2.1
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect error/warning at compile-time Test Case: deriving/should_compile/T14094
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3828
Wiki Page:

Description

Consider this code:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wall #-}
module Bug where

class C a where
  type T a
  data D a
  m :: a

instance C Int
deriving instance C Bool

Neither C instance implements any of its type families or methods. However, the manual C Int instance and the derived C Bool instance give different warnings:

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

Bug.hs:12:1: warning: [-Wmissing-methods]
    • No explicit associated type or default declaration for      ‘T’
    • In the instance declaration for ‘C Int’
   |
12 | instance C Int
   | ^^^^^^^^^^^^^^

Bug.hs:12:1: warning: [-Wmissing-methods]
    • No explicit associated type or default declaration for      ‘D’
    • In the instance declaration for ‘C Int’
   |
12 | instance C Int
   | ^^^^^^^^^^^^^^

Bug.hs:12:10: warning: [-Wmissing-methods]
    • No explicit implementation for
        ‘m’
    • In the instance declaration for ‘C Int’
   |
12 | instance C Int
   |          ^^^^^

Bug.hs:13:1: warning: [-Wmissing-methods]
    • No explicit implementation for
        ‘m’
    • In the instance declaration for ‘C Bool’
   |
13 | deriving instance C Bool
   | ^^^^^^^^^^^^^^^^^^^^^^^^

Notice that the C Int instance warns about the lack of an implementation for T and D, as expected. However, the derived C Bool instance does not. It only warns about m!

Change History (4)

comment:1 Changed 2 years ago by RyanGlScott

Owner: set to RyanGlScott

comment:2 Changed 2 years ago by RyanGlScott

Differential Rev(s): Phab:D3828
Status: newpatch

comment:3 Changed 2 years ago by Ryan Scott <ryan.gl.scott@…>

In 3f05e5f6/ghc:

Don't suppress unimplemented type family warnings with DeriveAnyClass

Summary:
For some asinine reason, we were suppressing warnings when
deriving associated type family instances with `DeriveAnyClass`. That seems
like a bad idea. Let's not do that.

Along the way, I noticed that the error contexts associated with these
newly emitted warnings were less than ideal, so I did some minor refactoring
to improve the story there.

Fixes #14094

Test Plan: ./validate

Reviewers: bgamari, austin

Subscribers: rwbarton, thomie

GHC Trac Issues: #14094

Differential Revision: https://phabricator.haskell.org/D3828

comment:4 Changed 2 years ago by RyanGlScott

Resolution: fixed
Status: patchclosed
Test Case: deriving/should_compile/T14094
Note: See TracTickets for help on using tickets.