Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#4877 closed bug (fixed)

Template Haskell panic when splicing an infix expression with a non-variable middle bit

Reported by: benmachine Owned by: simonpj
Priority: normal Milestone: 7.2.1
Component: Template Haskell Version: 7.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Simple enough:

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
panic = $(let var = varE . mkName in infixApp (var "x") (appE (var "f") (var "y")) (var "z"))
[1 of 1] Compiling Panic            ( Panic.hs, interpreted )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.0.1 for i386-unknown-linux):
	rnExpr: unexpected expression
    f{v} y{v}
      x{v} z{v}

Please report this as a GHC bug:

Of course the expression being spliced doesn't make any sense. In fact, I'd think that the only things that make sense in the centre of an infix expression were a single variable or constructor, so that field being of type Exp is arguably way too permissiveP. haskell-src seems to have a data type especially for this purpose - HsQOp with constructors HsQVarOp HsQName and HsQConOp HsQName.

Change History (7)

comment:1 Changed 9 years ago by igloo

Milestone: 7.0.3

Thanks for the report.

comment:2 Changed 9 years ago by simonmar

Owner: set to simonpj

comment:3 Changed 9 years ago by simonpj

Status: newmerge

This shouldn't crash, I agree. This fixes it

Wed Jan 12 17:07:19 GMT 2011
  * Produce an error message, not a crash, for HsOpApp with non-var operator
  Fixes Trac #4877.

    M ./compiler/rename/RnExpr.lhs -2 +6

But you're right that TH.Syntax should really only allow a variable there. I'll add it to the list on Template Haskell Proposal

comment:4 Changed 9 years ago by igloo

Resolution: fixed
Status: mergeclosed


comment:5 Changed 8 years ago by NeilMitchell

The error message that was added was "Operator application with a non-variable operator" - I got that error message and was very confused (I resorted to reading the source code to figure out what it meant). I think it would be far clearer if it read "Infix application with a non-variable operator" - OpApp is an internal GHC detail which users of Template Haskell aren't aware of - they will have written InfixE.

comment:6 Changed 8 years ago by simonpj

OK I changed the error message as Neil suggests, to read:

Infix application with a non-variable operator: <blah>

comment:7 Changed 8 years ago by simonpj@…

commit 9fc03d37c67098ab9dfa9403ff2c94e640074a76

Author: Simon Peyton Jones <>
Date:   Tue Oct 4 09:26:11 2011 +0100

    Change error message slightly
    in response to Neil's suggestion on Trac #4877

 compiler/rename/RnExpr.lhs |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Note: See TracTickets for help on using tickets.