Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#13314 closed bug (fixed)

StandaloneDeriving and DeriveAnyClass don't work together

Reported by: chris-martin Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.2
Keywords: Generics, deriving Cc: RyanGlScott
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: #11509 Differential Rev(s):
Wiki Page:

Description (last modified by chris-martin)

I'm starting with the SPretty example from the DeriveAnyClass section in the GHC users guide:

#!/usr/bin/env stack
-- stack --resolver lts-8.0
{-# LANGUAGE DefaultSignatures, DeriveAnyClass, StandaloneDeriving #-}

import Prelude
import Numeric.Natural (Natural)

class SPretty a where
    sPpr :: a -> String
    default sPpr :: Show a => a -> String
    sPpr = show

I can write an empty instance for Natural:

instance SPretty Natural where

So then I would expect to be able to write an equivalent definition using StandaloneDeriving and DeriveAnyClass:

deriving instance SPretty Natural

But instead it fails with this error:

error:
    • Can't make a derived instance of ‘SPretty Natural’:
        The data constructors of ‘Natural’ are not all in scope
          so you cannot derive an instance for it
    • In the stand-alone deriving instance for ‘SPretty Natural’

It seems like this ought to work; I'm not sure why the constructors should need to be in scope, given that the instance can be derived trivially without defining any methods.

Change History (6)

comment:1 Changed 3 years ago by chris-martin

Description: modified (diff)

comment:2 Changed 3 years ago by chris-martin

Description: modified (diff)

comment:3 Changed 3 years ago by chris-martin

Description: modified (diff)

comment:4 Changed 3 years ago by rwbarton

Cc: RyanGlScott added
Resolution: fixed
Status: newclosed

Happily this works with the revamped DeriveAnyClass logic in HEAD.

comment:5 Changed 3 years ago by RyanGlScott

Keywords: Generics added

comment:6 Changed 2 years ago by RyanGlScott

Keywords: deriving added
Note: See TracTickets for help on using tickets.