@@ -158,8 +158,7 @@ getTypeLHsExpr tms e = do
158158 Nothing -> return Nothing
159159 where
160160 getSpanSource :: HsExpr GhcTc -> SpanSource
161− getSpanSource (HsLit U lit) = Lit (showGhc lit)
162− getSpanSource (HsOverLit U lit) = Lit (showGhc lit)
161+ getSpanSource xpr | isLit xpr = Lit (showGhc xpr)
163162 getSpanSource (HsVar U (L _ i)) = Named (getName i)
164163 getSpanSource (HsConLikeOut U (RealDataCon dc)) = Named (dataConName dc)
165164 getSpanSource RecordCon {rcon_con_name} = Named (getName rcon_con_name)
@@ -167,6 +166,36 @@ getTypeLHsExpr tms e = do
167166 getSpanSource (HsPar U xpr) = getSpanSource (unLoc xpr)
168167 getSpanSource _ = NoSource
169168
169+ isLit :: HsExpr GhcTc -> Bool
170+ isLit (HsLit U _) = True
171+ isLit (HsOverLit U _) = True
172+ isLit (ExplicitTuple U args _) = all (isTupLit . unLoc) args
173+#if MIN_GHC_API_VERSION(8,6,0)
174+ isLit (ExplicitSum U _ _ xpr) = isLitChild (unLoc xpr)
175+ isLit (ExplicitList U _ xprs) = all (isLitChild . unLoc) xprs
176+#else
177+ isLit (ExplicitSum _ _ xpr _) = isLitChild (unLoc xpr)
178+ isLit (ExplicitList _ _ xprs) = all (isLitChild . unLoc) xprs
179+#endif
180+ isLit _ = False
181+
182+ isTupLit (Present U xpr) = isLitChild (unLoc xpr)
183+ isTupLit _ = False
184+
185+ -- We need special treatment for children so things like [(1)] are still treated
186+ -- as a list literal while not treating (1) as a literal.
187+ isLitChild (HsWrap U _ xpr) = isLitChild xpr
188+ isLitChild (HsPar U xpr) = isLitChild (unLoc xpr)
189+#if MIN_GHC_API_VERSION(8,8,0)
190+ isLitChild (ExprWithTySig U xpr _) = isLitChild (unLoc xpr)
191+#elif MIN_GHC_API_VERSION(8,6,0)
192+ isLitChild (ExprWithTySig U xpr) = isLitChild (unLoc xpr)
193+#else
194+ isLitChild (ExprWithTySigOut xpr _) = isLitChild (unLoc xpr)
195+ isLitChild (ExprWithTySig xpr _) = isLitChild (unLoc xpr)
196+#endif
197+ isLitChild e = isLit e
198+
170199-- | Get the name and type of a pattern.
171200getTypeLPat :: (GhcMonad m)
172201 => [TypecheckedModule]