Avoid find_tycon panic if datacon is not in scope
authorAdam Gundry <adam@well-typed.com>
Fri, 30 Dec 2016 02:30:41 +0000 (02:30 +0000)
committerRaspbian forward porter <root@raspbian.org>
Fri, 30 Dec 2016 02:30:41 +0000 (02:30 +0000)
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.

Reviewers: austin, bgamari
Reviewed By: bgamari
Differential Revision: https://phabricator.haskell.org/D2321
GHC Trac Issues: #12130

Origin: upstream, https://git.haskell.org/ghc.git/commitdiff/694e0f3a08030

Gbp-Pq: Name find-tycon-panic

compiler/rename/RnPat.hs

index 51ddea95fcb8ac45f8380d2e9502971a1fa2c68b..f1b61e3404ef5b75d2948f3133e6a4467a99cf6f 100644 (file)
@@ -636,7 +636,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
@@ -648,8 +648,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