#12933 closed bug (duplicate)

Wrong class instance selection with Data.Kind.Type

Reported by: julm Owned by:
Priority: highest Milestone:
Component: Compiler Version: 8.0.1
Keywords: TypeInType Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

If you consider the following code:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleInstances #-}
module Bug where

import GHC.Exts (Constraint)
import Data.Kind

-- | Partial singleton for a kind type.
data SKind k where
  SKiTy :: SKind Type
  SKiCo :: SKind Constraint

instance Show (SKind k) where
  show SKiTy = "*"
  show SKiCo = "Constraint"

class IKind k where
  kind :: SKind k
instance IKind Constraint where
  kind = SKiCo

Then, the main below will compile even though there is no (IKind Type) instance, and it will print "Constraint" two times, instead of an expected "Constraint" then "*":

main :: IO ()
main = do
  print (kind::SKind Constraint)
  print (kind::SKind Type)

And, the main below will print "*" two times, instead of an expected "*" then "Constraint":

instance IKind Type where
  kind = SKiTy

main :: IO ()
main = do
  print (kind::SKind Type)
  print (kind::SKind Constraint)

This can be worked around by replacing Type with a new data type Ty to select the right class instances, using two type families Ty_of_Type and Type_of_Ty, as done in the attached Workaround.hs.

Sorry if this bug has already been fixed in HEAD: I was unable to find neither a bug report similar, nor a Linux x86_64 build of HEAD for me to test.

Attachments (1)

Workaround.hs (1.5 KB) - added by julm 12 months ago.

Download all attachments as: .zip

Change History (3)

Changed 12 months ago by julm

Attachment: Workaround.hs added

comment:1 Changed 12 months ago by mpickering

Related to #11715 perhaps?

comment:2 Changed 12 months ago by goldfire

Resolution: duplicate
Status: newclosed

Yes -- this is an instance of #11715.

Thanks for including this example, which I will link to from #11715.

Note: See TracTickets for help on using tickets.