Opened 12 months ago

Closed 5 months ago

Last modified 5 months ago

#14627 closed bug (fixed)

qAddTopDecls: can't convert top-level declarations

Reported by: tianxiaogu Owned by: mgsloan
Priority: normal Milestone: 8.8.1
Component: Template Haskell Version: 8.2.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time crash or panic Test Case: th/T14627
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D4914
Wiki Page:

Description

The following program crashes 8.2.2 and HEAD (8.5.20171228).

{-# LANGUAGE TemplateHaskell #-}
import           Language.Haskell.TH.Syntax         (addTopDecls)
$(do
    ds <- [d| f = Bool
            |]
    addTopDecls ds
    [d| g = cab
      |])

Output:

    Exception when trying to run compile-time code:
      ghc: panic! (the 'impossible' happened)
  (GHC version 8.5.20171228 for x86_64-unknown-linux):
	qAddTopDecls: can't convert top-level declarations

Illegal variable name: ‘Bool’
When splicing a TH declaration: f_0 = Bool
Call stack:
    CallStack (from HasCallStack):
      callStackDoc, called at compiler/utils/Outputable.hs:1150:37 in ghc:Outputable
      pprPanic, called at compiler/typecheck/TcSplice.hs:886:27 in ghc:TcSplice

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Change History (11)

comment:1 Changed 12 months ago by RyanGlScott

Architecture: x86_64 (amd64)Unknown/Multiple
Component: CompilerTemplate Haskell
Operating System: LinuxUnknown/Multiple

comment:2 Changed 6 months ago by mgsloan

Owner: set to mgsloan

comment:3 Changed 6 months ago by mgsloan

I've put up a patch that makes addTopDelcs no longer panic for conversion errors: https://phabricator.haskell.org/D4914 . Instead they are reported as normal errors like this:

T14627.hs:3:3: error:
    qAddTopDecls: can't convert declarations:
      Illegal variable name: ‘Bool’
      When splicing a TH declaration: f_0 = Bool
  |
3 | $(do
  |   ^^...

Atop this, the error "Illegal variable name: 'Bool'" is quite poor, instead it should just say there's an out of scope constructor. I have a patch that fixes this and adds documentation to UnboundVarE clarifying this case. Can't push it to phabricator yet, though, because it appears to be down.

comment:4 Changed 6 months ago by goldfire

Differential Rev(s): Phab:D4914

comment:5 Changed 6 months ago by mgsloan

In addition to D4914, which changes this from panic-ing to just a regular error, I've also published https://phabricator.haskell.org/D4923 which improves the error for this specific case. Instead it says "Data constructor not in scope: Bool"

comment:6 Changed 6 months ago by mgsloan

Cc: th/T14627 added
Status: newpatch

comment:7 Changed 6 months ago by mgsloan

Cc: th/T14627 removed
Test Case: th/T14627

comment:8 Changed 5 months ago by Ben Gamari <ben@…>

In 0f79b0e/ghc:

Fix handling of unbound constructor names in TH #14627

Also adds a comment to UnboundVarE clarifying that it also is used for
unbound constructor identifiers, since that isn't very clear from the
name.

Test Plan: testsuite/tests/th/T14627.hs

Reviewers: goldfire, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4923

comment:9 Changed 5 months ago by bgamari

Milestone: 8.6.1
Resolution: fixed
Status: patchclosed

comment:10 Changed 5 months ago by bgamari

Milestone: 8.6.18.8.1

comment:11 Changed 5 months ago by Ben Gamari <ben@…>

In 774f366/ghc:

Fail instead of panic-ing when qAddTopDecls has conversion error

See https://ghc.haskell.org/trac/ghc/ticket/14627 for an example where
GHC panics when using qAddTopDecls on [d| f = Bool |]. Instead, it
should be a normal error message, and that's what this change is for. It
does not entirely resolve Trac#14627, since "Illegal variable name:
'bool'" isn't a very good error for this cirumstance.

Test Plan: Manually tested.

Reviewers: goldfire, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4914
Note: See TracTickets for help on using tickets.