While developing a typechecker plugin, I experienced this error message.
> ghc: panic! (the 'impossible' happened)
> (GHC version 8.6.2 for x86_64-unknown-linux):
> flatten_args wandered into deeper water than usual
> Call stack:
> CallStack (from HasCallStack):
> callStackDoc, called at compiler/utils/Outputable.hs:1160:37 in ghc:Outputable
> pprPanic, called at compiler/typecheck/TcFlatten.hs:1331:24 in ghc:TcFlatten
>
I'm sending this email just in case a dev is curious how this panic arises or if another plugin developer sees the same thing -- the error message is not very informative, and the corresponding GHC source code is a bit obtuse.
Based on the relevant GHC source code and my recent plugin edits, I was able to guess correctly that this was due to me generating an extra sort argument to a promoted datacon. Specifically, I was incorrectly using
> mkTyConApp (promoteDataCon _) [typeKind k,k,...]
instead of just
> mkTyConApp (promoteDataCon _) [k,...]
Thanks! HTH. -Nick