Commit 4d71cc89 authored by Adam Gundry's avatar Adam Gundry Committed by Ben Gamari

Avoid find_tycon panic if datacon is not in scope

When using TH to splice expressions involving record field construction,
the parent datacon may not be in scope.  We shouldn't panic about this,
because we will be renaming Exact RdrNames which don't require any
disambiguation.

Test Plan: new test th/T12130

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: thomie

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

GHC Trac Issues: #12130
parent 9649fc0a
......@@ -635,7 +635,7 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot })
find_tycon :: GlobalRdrEnv -> Name {- DataCon -} -> Maybe Name {- TyCon -}
-- Return the parent *type constructor* of the data constructor
-- (that is, the parent of the data constructor),
-- or 'Nothing' if it is a pattern synonym.
-- or 'Nothing' if it is a pattern synonym or not in scope.
-- That's the parent to use for looking up record fields.
find_tycon env con
| Just (AConLike (RealDataCon dc)) <- wiredInNameTyThing_maybe con
......@@ -647,8 +647,9 @@ rnHsRecFields ctxt mk_arg (HsRecFields { rec_flds = flds, rec_dotdot = dotdot })
ParentIs p -> Just p
_ -> Nothing
| otherwise
= pprPanic "find_tycon" (ppr con $$ ppr (lookupGRE_Name env con))
| otherwise = Nothing
-- This can happen if the datacon is not in scope
-- and we are in a TH splice (Trac #12130)
dup_flds :: [[RdrName]]
-- Each list represents a RdrName that occurred more than once
......
{-# Language TemplateHaskell #-}
{-# Language DisambiguateRecordFields #-}
module T12130 where
import T12130a hiding (Block)
b = $(block)
{-# LANGUAGE TemplateHaskell #-}
module T12130a where
import Language.Haskell.TH
data Block = Block
{ blockSelector :: ()
}
block :: Q Exp
block =
[| Block {
-- Using record syntax is neccesary to trigger the bug.
blockSelector = ()
}
|]
......@@ -407,3 +407,5 @@ test('T11941', normal, compile_fail, ['-v0'])
test('T11484', normal, compile, ['-v0'])
test('T8761', unless(ghc_dynamic(), expect_broken(12077)), compile,
['-v0 -ddump-splices -dsuppress-uniques'])
test('T12130', extra_clean(['T12130a.hi','T12130a.o']),
multimod_compile, ['T12130', '-v0 ' + config.ghc_th_way_flags])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment