Opened 8 years ago

Closed 4 years ago

#4124 closed bug (fixed)

GHC rejects instance quotations with splices in the instance head

Reported by: lilac Owned by:
Priority: low Milestone: 7.6.2
Component: Template Haskell Version: 6.12.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case: th/4124
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I think the following code should be accepted.

{-# LANGUAGE TemplateHaskell #-}
class Storable a where
data X = X
[d| instance Storable $( [t| X |] ) where |]

GHC disagrees, saying:

test.hs:4:4:
    Illegal instance declaration for `Storable t_aKj'
        (All instance types must be of the form (T a1 ... an)
         where a1 ... an are type *variables*,
         and each type variable appears at most once in the instance head.
         Use -XFlexibleInstances if you want to disable this.)
    In the instance declaration for `Storable $[t| X |]'
    In the Template Haskell quotation
      [d| 
          instance Storable $[t| X |] where |]
    In the expression:
        [d| 
            instance Storable $[t| X |] where |]

This checking seems inappropriate before the type is actually spliced in!

Change History (11)

comment:1 Changed 8 years ago by lilac

Some quick checking indicates the error message is using invalid syntax too: $[t| X |] is not accepted by GHC.

comment:2 Changed 8 years ago by igloo

Milestone: 6.14.1

comment:3 Changed 8 years ago by igloo

I've fixed the pretty-printer so that it doesn't print $[t| X |].

comment:4 Changed 7 years ago by simonpj

Blocked By: 4230 added

This too is related to #4230.

comment:5 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:6 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:7 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:8 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:9 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:10 Changed 4 years ago by Krzysztof Gogolewski <krz.gogolewski@…>

In e595c81ee0951f17d34b918123dfa7711710fe89/testsuite:

Add tests for new TH #4124, #4128, #4170, #4364, #6062

comment:11 Changed 4 years ago by monoidal

Blocked By: 4230 removed
difficulty: Unknown
Resolution: fixed
Status: newclosed
Test Case: th/4124

This is now fixed thanks to new TH.

BTW for older GHC you could work around it by enabling -XFlexibleInstances (as the error suggests), but that was unneccessary and is now not needed.

Note: See TracTickets for help on using tickets.