@@ -13,6 +13,7 @@ module Wingman.CodeGen
1313import ConLike
1414import Control.Lens ((%~) , (<>~) , (&) )
1515import Control.Monad.Except
16+ import Control.Monad.Reader (ask )
1617import Control.Monad.State
1718import Data.Bool (bool )
1819import Data.Functor ((<&>) )
@@ -24,6 +25,7 @@ import Data.Traversable
2425import DataCon
2526import Development.IDE.GHC.Compat
2627import GHC.Exts
28+ import GHC.SourceGen (occNameToStr )
2729import GHC.SourceGen.Binds
2830import GHC.SourceGen.Expr
2931import GHC.SourceGen.Overloaded
@@ -39,7 +41,6 @@ import Wingman.Judgements.Theta
3941import Wingman.Machinery
4042import Wingman.Naming
4143import Wingman.Types
42- import GHC.SourceGen (occNameToStr )
4344
4445
4546destructMatches
@@ -69,6 +70,7 @@ destructMatches use_field_puns f scrut t jdg = do
6970 args = conLikeInstOrigArgTys' con apps
7071 modify $ appEndo $ foldMap (Endo . evidenceToSubst) ev
7172 subst <- gets ts_unifier
73+ ctx <- ask
7274
7375 let names_in_scope = hyNamesInScope hy
7476 names = mkManyGoodNames (hyNamesInScope hy) args
@@ -79,8 +81,8 @@ destructMatches use_field_puns f scrut t jdg = do
7981 $ zip names'
8082 $ coerce args
8183 j = fmap (CType . substTyAddInScope subst . unCType)
82- $ introduce hy'
83- $ introduce method_hy
84+ $ introduce ctx hy'
85+ $ introduce ctx method_hy
8486 $ withNewGoal g jdg
8587 ext <- f con j
8688 pure $ ext
@@ -289,13 +291,14 @@ letForEach rename solve (unHypothesis -> hy) jdg = do
289291 case hy of
290292 [] -> newSubgoal jdg
291293 _ -> do
294+ ctx <- ask
292295 let g = jGoal jdg
293296 terms <- fmap sequenceA $ for hy $ \ hi -> do
294297 let name = rename $ hi_name hi
295298 res <- tacticToRule jdg $ solve hi
296299 pure $ fmap ((name,) . unLoc) res
297300 let hy' = fmap (g <$ ) $ syn_val terms
298301 matches = fmap (fmap (\ (occ, expr) -> valBind (occNameToStr occ) expr)) terms
299- g <- fmap (fmap unLoc) $ newSubgoal $ introduce (userHypothesis hy') jdg
302+ g <- fmap (fmap unLoc) $ newSubgoal $ introduce ctx (userHypothesis hy') jdg
300303 pure $ fmap noLoc $ let' <$> matches <*> g
301304
0 commit comments