Ticket #3395 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

Template Haskell crashes

Reported by: NeilMitchell Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.10.4
Keywords: Cc: ndmitchell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: th/T3395 Blocked By:
Blocking: Related Tickets:

Description

The following fragment:

{-# LANGUAGE TemplateHaskell #-}

import Language.Haskell.TH

foo = $(return $ 
    CompE
        [NoBindS (VarE $ mkName "undefined")
        ,BindS (VarP $ mkName "r1") (VarE $ mkName "undefined") ])

when loaded gives:

*** Exception: hsSyn\Convert.lhs:(427,14)-(428,33): Non-exhaustive patterns in case

Change History

Changed 4 years ago by NeilMitchell

As a hint for anyone wanting to work around this bug, converting the list comp to a do block does work.

Changed 4 years ago by igloo

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to fixed

Thanks for the report.

This represents

[r1 <- undefined | undefined]

i.e. it generates incorrect Haskell.

The HEAD gives a

ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 6.11.20090722 for x86_64-unknown-linux):
        Malformed body

error.

Changed 4 years ago by NeilMitchell

The order for CompE is non-intuitive, most other Template Haskell expressions follow their syntactic representation for order, but this doesn't. Could a note be added to the documentation?

Changed 4 years ago by simonpj

  • testcase set to th/T3395

I've improved error reporting when this kind of thing happens

Tue Aug 11 07:36:55 PDT 2009  simonpj@microsoft.com
  * Refactor, and improve error messages (cf Trac #3395)
  Ignore-this: e7205f5bcf8408ff791ba19156e48461
  
  The Convert stuff should not panic if the programmer hands over an
  invalid TH term; instead it should give a graceful error message.
  Largely this had been done, but not for do-blocks, so this patch
  fixes that problem.
  
  Moreover, I did some refactoring and tidying up, which is why
  so many lines of code have changed
  

    M ./compiler/hsSyn/Convert.lhs -153 +146

Changed 4 years ago by simonpj

In the template-haskell library, I've also added a Haddock's documentation note to the Exp type about how to use CompE.

Thu Aug 13 16:29:41 BST 2009  simonpj@microsoft.com
  * Document 'CompE' better (see Trac #3395)

Simon

Note: See TracTickets for help on using tickets.