Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#11265 closed bug (fixed)

Internal error, using pattern synonym as instance head

Reported by: Iceland_jack Owned by: simonpj
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.10.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: patsyn/should_fail/T11265
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

{-# LANGUAGE PatternSynonyms, DataKinds #-}

pattern A = True

class    F a
instance F A

when loaded in ghci it results in an internal error

% g internal.hs
GHCi, version 7.11.20151216:  :? for help
[1 of 1] Compiling Main             ( internal.hs, interpreted )

internal.hs:5:12: error:
     GHC internal error: A is not in scope during type checking, but it passed the renamer
      tcl_env of environment: []
     In the first argument of F, namely A
      In the instance declaration for F A
Failed, modules loaded: none.

Change History (5)

comment:1 Changed 3 years ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 3 years ago by goldfire

Owner: set to goldfire

This smells like my fault, but it also looks quite easy to fix.

comment:3 Changed 3 years ago by simonpj

Owner: changed from goldfire to simonpj

Actually it's not your fault. I'm on it.

comment:4 Changed 3 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: patsyn/should_fail/T11265

Thanks for reporting this, with a nice small repro case.

Fixed by

commit c069be815aa0bce2eb2c9621a36f114badda2318
Author: Simon Peyton Jones <>
Date:   Mon Dec 21 14:18:32 2015 +0000

    Add a pattern-syn form of PromotionErr
    The main change is to add PatSynPE to PromotionErr, so that
    when we get an ill-staged use of a pattern synonym we get a
    civilised error message.
    We were already doing this in half-baked form in tcValBinds, but
    this patch tidies up the impl (which previously used a hack rather
    than APromotionErr), and does it in tcTyClsInstDecls too.


 compiler/hsSyn/HsBinds.hs                         |  15 ----
 compiler/typecheck/TcBinds.hs                     |  53 +++--------
 compiler/typecheck/TcEnv.hs                       | 103 +++++++++++++++++++++-
 compiler/typecheck/TcHsType.hs                    |   1 +
 compiler/typecheck/TcRnDriver.hs                  |  80 ++++++-----------
 compiler/typecheck/TcRnTypes.hs                   |   5 ++
 testsuite/tests/patsyn/should_fail/T11265.hs      |   6 ++
 testsuite/tests/patsyn/should_fail/T11265.stderr  |   6 ++
 testsuite/tests/patsyn/should_fail/T9161-1.stderr |   7 +-
 testsuite/tests/patsyn/should_fail/T9161-2.stderr |   3 +-
 testsuite/tests/patsyn/should_fail/all.T          |   1 +
 11 files changed, 163 insertions(+), 117 deletions(-)

comment:5 Changed 3 years ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.