[Git][ghc/ghc][wip/mangoiv/28038] fixup! typechecker: use safe lookup for lookupMBI
Magnus pushed to branch wip/mangoiv/28038 at Glasgow Haskell Compiler / GHC Commits: bf0ef07b by mangoiv at 2026-11-23T17:57:20+01:00 fixup! typechecker: use safe lookup for lookupMBI - - - - - 4 changed files: - changelog.d/28038 - compiler/GHC/Tc/Gen/Bind.hs - compiler/GHC/Tc/TyCl/PatSyn.hs - compiler/GHC/Tc/Utils/Env.hs Changes: ===================================== changelog.d/28038 ===================================== @@ -1,12 +1,8 @@ section: compiler synopsis: - Fix a panic when trying to bind a type variable in patterns. + When encountering a required type argument in a pattern binding, don't panic, report an error instead. description: - GHC currently does not allow to bind type variables in patterns. When - a user would try that, in some situations, we didn't abort eagerly - enough after discovering the error and thus ran into a panic looking up - the type in the env while trying to update the local context. Instead, - when discovering the error, - we now abort eagerly. + GHC does not currently support pattern bindings that bind a required type argument. Now GHC reports an + error in that situation, instead of panicking. mrs: !16868 issues: #28038 ===================================== compiler/GHC/Tc/Gen/Bind.hs ===================================== @@ -1557,8 +1557,8 @@ lookupMBI :: Name -> TcM MonoBindInfo lookupMBI name = do { mono_id_e <- tcLookupTermBndr name ; case mono_id_e of - Left _ -> failIllegalTyVar (noUserRdr name) - Right mono_id -> + TyVarBndr _ -> failIllegalTyVar (noUserRdr name) + TermBndr mono_id -> return (MBI { mbi_poly_name = name , mbi_sig = Nothing , mbi_mono_id = mono_id ===================================== compiler/GHC/Tc/TyCl/PatSyn.hs ===================================== @@ -652,8 +652,8 @@ collectPatSynArgInfo details = tcLookupPatSynArg :: Name -> TcM Id tcLookupPatSynArg arg_name = do { tcLookupTermBndr arg_name >>= \ case - Left (ButATyVar _var) -> failIllegalTyVar (noUserRdr arg_name) - Right id -> return id } + TyVarBndr{} -> failIllegalTyVar (noUserRdr arg_name) + TermBndr id -> return id } wrongNumberOfParmsErr :: Name -> Arity -> Arity -> TcM a wrongNumberOfParmsErr name decl_arity missing ===================================== compiler/GHC/Tc/Utils/Env.hs ===================================== @@ -43,7 +43,7 @@ module GHC.Tc.Utils.Env( tcLookup, tcLookupLocated, tcLookupLocalIds, tcLookupId, tcLookupIdMaybe, tcLookupTyVar, - tcLookupTermBndr, NotATermBndr (..), + tcLookupTermBndr, TermBndr (..), tcLookupTcTyCon, tcLookupLcl_maybe, getInLocalScope, @@ -769,16 +769,17 @@ tcLookupIdMaybe name -- | Encountered a thing that is not a term binder when -- calling 'tcLookupTermBndr'. -newtype NotATermBndr - = ButATyVar TcTyVar +data TermBndr + = TermBndr !Id + | TyVarBndr !TcTyVar -tcLookupTermBndr :: Name -> TcM (Either NotATermBndr Id) +tcLookupTermBndr :: Name -> TcM TermBndr tcLookupTermBndr name = do thing <- tcLookup name case thing of - ATcId { tct_id } -> pure $ Right $! tct_id - AGlobal (AnId id) -> pure $ Right $! id - ATyVar _ var -> pure $ Left $! ButATyVar var + ATcId { tct_id } -> pure $ TermBndr tct_id + AGlobal (AnId id) -> pure $ TermBndr id + ATyVar _ var -> pure $ TyVarBndr var _ -> pprPanic "tcLookupTermBndr: unexpected thing" (ppr thing) tcLookupLocalIds :: [Name] -> TcM [TcId] View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf0ef07b974ef5f28b522c952fe50ad0... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf0ef07b974ef5f28b522c952fe50ad0... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Magnus (@MangoIV)