In-scope assertion failure with type application
This program causes an assertion failure on master, as of dd39bdc0:
module T23918 where
import Data.Kind
f :: forall (a :: Type). a -> a
f = g @a
g :: forall (k :: Type) (a :: Type) (r :: k). a -> a
g = g
./stage1/bin/ghc T23918
[1 of 1] Compiling T23918 ( T23918.hs, T23918.o )
<no location info>: error:
panic! (the 'impossible' happened)
GHC version 9.9.20230831:
ASSERT failed!
in_scope InScope {a_axA}
tenv [awA :-> a_axA[tau:1]]
cenv []
tys [a_axx[sk:1]]
cos []
needInScope {a_axx[sk:1]}
Call stack:
CallStack (from HasCallStack):
assertPpr, called at compiler/GHC/Core/TyCo/Subst.hs:696:5 in ghc-9.9-inplace:GHC.Core.TyCo.Subst
checkValidSubst, called at compiler/GHC/Core/TyCo/Subst.hs:720:29 in ghc-9.9-inplace:GHC.Core.TyCo.Subst
substTy, called at compiler/GHC/Tc/Utils/TcMType.hs:1058:19 in ghc-9.9-inplace:GHC.Tc.Utils.TcMType
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:512:29 in ghc-9.9-inplace:GHC.Utils.Error
Originally found while investigating #23914 (closed) but it's independent of that ticket.