@@ -273,7 +273,7 @@ mkJudgementAndContext cfg g (TrackedStale binds bmap) rss (TrackedStale tcg tcgm
273
273
mkFirstJudgement
274
274
ctx
275
275
(local_hy <> cls_hy)
276
- (isRhsHole tcg_rss tcs)
276
+ (isRhsHoleWithoutWhere tcg_rss tcs)
277
277
g
278
278
, ctx
279
279
)
@@ -341,6 +341,7 @@ getRhsPosVals (unTrack -> rss) (unTrack -> tcs)
341
341
TopLevelRHS name ps
342
342
(L (RealSrcSpan span ) -- body with no guards and a single defn
343
343
(HsVar _ (L _ hole)))
344
+ _
344
345
| containsSpan rss span -- which contains our span
345
346
, isHole $ occName hole -- and the span is a hole
346
347
-> flip evalState 0 $ buildTopLevelHypothesis name ps
@@ -478,12 +479,25 @@ mkIdHypothesis (splitId -> (name, ty)) prov =
478
479
479
480
480
481
------------------------------------------------------------------------------
481
- -- | Is this hole immediately to the right of an equals sign?
482
- isRhsHole :: Tracked age RealSrcSpan -> Tracked age TypecheckedSource -> Bool
483
- isRhsHole (unTrack -> rss) (unTrack -> tcs) =
482
+ -- | Is this hole immediately to the right of an equals sign --- and is there
483
+ -- no where clause attached to it?
484
+ --
485
+ -- It's important that there is no where clause because otherwise it gets
486
+ -- clobbered. See #2183 for an example.
487
+ --
488
+ -- This isn't a perfect check, and produces some ugly code. But it's much much
489
+ -- better than the alternative, which is to destructively modify the user's
490
+ -- AST.
491
+ isRhsHoleWithoutWhere
492
+ :: Tracked age RealSrcSpan
493
+ -> Tracked age TypecheckedSource
494
+ -> Bool
495
+ isRhsHoleWithoutWhere (unTrack -> rss) (unTrack -> tcs) =
484
496
everything (||) (mkQ False $ \ case
485
- TopLevelRHS _ _ (L (RealSrcSpan span ) _) -> containsSpan rss span
486
- _ -> False
497
+ TopLevelRHS _ _
498
+ (L (RealSrcSpan span ) _)
499
+ (EmptyLocalBinds _) -> containsSpan rss span
500
+ _ -> False
487
501
) tcs
488
502
489
503
0 commit comments