in_scope ASSERT failure when desugaring GADT record update
The following module causes an ASSERT failure on HEAD:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
module RepPolyGADTRecordUpdate where
import Data.Kind
import GHC.Exts
type X :: TYPE rep -> Type
data X a where
MkX :: { fld1 :: a, fld2 :: Int } -> X a
upd :: forall rep (a :: TYPE rep). X a -> X a
upd x = x { fld2 = 3 }
ghc: panic! (the 'impossible' happened)
GHC version 9.3.20210824:
ASSERT failed!
in_scope InScope {rep_azw a_azx}
tenv [aiR :-> a_azx, awI :-> rep_azw]
cenv []
tys [rep_awI ~# 'BoxedRep 'Lifted, a_aiR ~# a_X0]
cos []
needInScope {a_X0}
Call stack:
CallStack (from HasCallStack):
assertPpr, called at compiler/GHC/Core/TyCo/Subst.hs:<line>:<column> in <package-id>:GHC.Core.TyCo.Subst
checkValidSubst, called at compiler/GHC/Core/TyCo/Subst.hs:<line>:<column> in <package-id>:GHC.Core.TyCo.Subst
substTys, called at compiler/GHC/Core/TyCo/Subst.hs:<line>:<column> in <package-id>:GHC.Core.TyCo.Subst
substTheta, called at compiler/GHC/HsToCore/Expr.hs:<line>:<column> in <package-id>:GHC.HsToCore.Expr
The callstack indicates that this happens in a call to substTheta
in the RecordUpd
case of GHC.HsToCore.Expr.dsExpr
, which indeed desugars GADT record upates.