Skip to content

Backpack creashes on default type families #6153

@Raelifin

Description

@Raelifin

If I create a class with an associated type family that has a default type, cabal crashes if I try to demand an instance of this class in a signature file. In particular it says:

<no location info>: error:
    The identifier R:BarStr does not exist in the local signature.
    (Try adding it to the export list of the hsig file.)

where Bar is the type family associated with the type Str.

To reproduce, we'll start with https://github.com/ezyang/backpack-regex-example/tree/better-single-package
Then apply this diff:

diff --git a/regex-example.cabal b/regex-example.cabal
index 18cebd3..68ea75b 100644
--- a/regex-example.cabal
+++ b/regex-example.cabal
@@ -9,7 +9,7 @@ library str-impls
   hs-source-dirs:      str-impls
 
 library regex-types
-  build-depends:       base
+  build-depends:       base, bytestring
   exposed-modules:     Regex.Types
   hs-source-dirs:      regex-types
 
diff --git a/regex-indef/Str.hsig b/regex-indef/Str.hsig
index 23bfb8c..6e2aa0b 100644
--- a/regex-indef/Str.hsig
+++ b/regex-indef/Str.hsig
@@ -1,7 +1,9 @@
 signature Str where
+import Regex.Types
 
 data Str
 instance Eq Str
+instance Foo Str
 
 null :: Str -> Bool
 singleton :: Char -> Str
diff --git a/regex-types/Regex/Types.hs b/regex-types/Regex/Types.hs
index 2900749..4fe4eb0 100644
--- a/regex-types/Regex/Types.hs
+++ b/regex-types/Regex/Types.hs
@@ -1,7 +1,16 @@
+{-# LANGUAGE FlexibleInstances, TypeFamilies #-}
 module Regex.Types where
+import Data.ByteString
 
 data Reg = Eps
          | Sym Char
          | Alt Reg Reg
          | Seq Reg Reg
          | Rep Reg
+
+class Foo x where
+  type Bar x :: *
+  type Bar x = ()
+
+instance Foo String
+instance Foo ByteString

and run cabal v1-build or cabal v2-build in the project directory.

I'm running GHC 8.6.5 and Cabal 2.4.1.0.

@ezyang ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions