Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#13759 closed bug (duplicate)

Strange error message for deriving Data

Reported by: alanz Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.3
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #12245 Differential Rev(s):
Wiki Page:

Description

The following code

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleInstances #-}

import Data.Data

data Pass = Parsed | Renamed | Typechecked
         deriving (Data)

data GHC (c :: Pass)

deriving instance Data (GHC 'Parsed)
deriving instance Data (GHC 'Renamed)
deriving instance Data (GHC 'Typechecked)

-- Type synonyms as a shorthand for tagging
type GhcPs  = GHC 'Parsed
type GhcRn  = GHC 'Renamed
type GhcTc  = GHC 'Typechecked

loads fine in ghci-8.2.0.20170507.

In ghc-8.0.2 and current master (as at https://github.com/ghc/ghc/tree/wip/new-tree-one-param-2) it gives

alanz@alanz-laptop:~/tmp/ghc-bug-data-deriving$ ghci-8.0.2 Main.hs 
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/alanz/.ghci
[1 of 1] Compiling Main             ( Main.hs, interpreted )

Main.hs:16:1: error:
    Multiple declarations of $tFl4AgeEJ0Vk5ONrnm56S3r
    Declared at: Main.hs:16:1
                 Main.hs:17:1

Main.hs:16:1: error:
    Multiple declarations of $tFl4AgeEJ0Vk5ONrnm56S3r
    Declared at: Main.hs:15:1
                 Main.hs:17:1

Main.hs:16:1: error:
    Duplicate type signatures for $tFl4AgeEJ0Vk5ONrnm56S3r
    at Main.hs:15:1-36
       Main.hs:16:1-37
       Main.hs:17:1-41
Failed, modules loaded: none.

Change History (4)

comment:1 Changed 2 years ago by RyanGlScott

I'm not sure what changes you did on your local branch to make this fail, but on GHC HEAD (as of commit 09d5c993aae208e3d34a9e715297922b6ea42b3f), that program typechecks.

Do you have commit 895eefa8447a2886e77fdedcbca8047263c88db7 (Make unique auxiliary function names in deriving) in your local branch? That's what fixed #12245, which I would consider this ticket to be a duplicate of.

comment:2 Changed 2 years ago by RyanGlScott

alanz helped me figure out what was going on. You won't hit the bug with the original code, but you will with this slightly tweaked code:

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleInstances #-}

import Data.Data

data Pass = Parsed | Renamed | Typechecked
         deriving (Data)

data GHC (c :: Pass)

deriving instance Data GhcPs
deriving instance Data GhcRn
deriving instance Data GhcTc

-- Type synonyms as a shorthand for tagging
type GhcPs  = GHC 'Parsed
type GhcRn  = GHC 'Renamed
type GhcTc  = GHC 'Typechecked

Crucially, we're deriving instances for the type synonyms.

comment:3 Changed 2 years ago by RyanGlScott

Resolution: duplicate
Status: newclosed

Please ignore what I wrote in comment:2, that is utter garbage. The real, real cause of what was going on is much simpler: it is indeed a duplicate of #12245. The reason that alanz hit this bug when building ​https://github.com/ghc/ghc/tree/wip/new-tree-one-param-2 was simply because he was bootstrapping with GHC 8.0.2, and the fix for #12245 didn't land until GHC 8.2.

comment:4 Changed 2 years ago by RyanGlScott

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