InScope set assertion failure from monad-skeleton
```
{-# LANGUAGE PolyKinds, GADTs, Rank2Types, ScopedTypeVariables, Trustworthy #-}
module Control.Monad.Skeleton.Internal where
data Cat k a b where
Empty :: Cat k a a
Leaf :: k a b -> Cat k a b
Tree :: Cat k a b -> Cat k b c -> Cat k a c
viewL :: forall k a b r. Cat k a b
-> ((a ~ b) => r)
-> (forall x. k a x -> Cat k x b -> r)
-> r
viewL Empty e _ = e
viewL (Leaf k) _ r = k `r` Empty
viewL (Tree a b) e r = go a b where
go :: Cat k a x -> Cat k x b -> r
go Empty t = viewL t e r
go (Leaf k) t = r k t
go (Tree c d) t = go c (Tree d t)
```
Leads to the assertion failure
```
[1 of 1] Compiling Control.Monad.Skeleton.Internal ( Internal.hs, Internal.o )
WARNING: file compiler/simplCore/OccurAnal.hs, line 2160 Just 3 []
ghc: panic! (the 'impossible' happened)
(GHC version 8.2.0.20170708 for x86_64-unknown-linux):
ASSERT failed!
in_scope InScope {x_avF ds_d14c}
tenv [avF :-> x_avF]
tenvFVs [avF :-> x_avF, a11Z :-> k_a11Z]
cenv []
cenvFVs []
tys [k1_a120 a_a121 x_avF]
cos []
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1188:22 in ghc:Outputable
assertPprPanic, called at compiler/types/TyCoRep.hs:2088:56 in ghc:TyCoRep
checkValidSubst, called at compiler/types/TyCoRep.hs:2121:29 in ghc:TyCoRep
substTy, called at compiler/coreSyn/CoreArity.hs:1197:19 in ghc:CoreArity
Call stack:
CallStack (from HasCallStack):
prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable
callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable
pprPanic, called at compiler/utils/Outputable.hs:1186:5 in ghc:Outputable
assertPprPanic, called at compiler/types/TyCoRep.hs:2088:56 in ghc:TyCoRep
checkValidSubst, called at compiler/types/TyCoRep.hs:2121:29 in ghc:TyCoRep
substTy, called at compiler/coreSyn/CoreArity.hs:1197:19 in ghc:CoreArity
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
```
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"InScope set assertion failure from monad-skeleton","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.3","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"{{{\r\n{-# LANGUAGE PolyKinds, GADTs, Rank2Types, ScopedTypeVariables, Trustworthy #-} \r\nmodule Control.Monad.Skeleton.Internal where \r\n \r\ndata Cat k a b where \r\n Empty :: Cat k a a \r\n Leaf :: k a b -> Cat k a b \r\n Tree :: Cat k a b -> Cat k b c -> Cat k a c \r\n \r\nviewL :: forall k a b r. Cat k a b \r\n -> ((a ~ b) => r) \r\n -> (forall x. k a x -> Cat k x b -> r) \r\n -> r \r\nviewL Empty e _ = e \r\nviewL (Leaf k) _ r = k `r` Empty \r\nviewL (Tree a b) e r = go a b where \r\n go :: Cat k a x -> Cat k x b -> r \r\n go Empty t = viewL t e r \r\n go (Leaf k) t = r k t \r\n go (Tree c d) t = go c (Tree d t)\r\n}}}\r\n\r\nLeads to the assertion failure\r\n\r\n{{{\r\n[1 of 1] Compiling Control.Monad.Skeleton.Internal ( Internal.hs, Internal.o )\r\nWARNING: file compiler/simplCore/OccurAnal.hs, line 2160 Just 3 []\r\nghc: panic! (the 'impossible' happened)\r\n (GHC version 8.2.0.20170708 for x86_64-unknown-linux):\r\n\tASSERT failed!\r\n in_scope InScope {x_avF ds_d14c}\r\n tenv [avF :-> x_avF]\r\n tenvFVs [avF :-> x_avF, a11Z :-> k_a11Z]\r\n cenv []\r\n cenvFVs []\r\n tys [k1_a120 a_a121 x_avF]\r\n cos []\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable\r\n callStackDoc, called at compiler/utils/Outputable.hs:1188:22 in ghc:Outputable\r\n assertPprPanic, called at compiler/types/TyCoRep.hs:2088:56 in ghc:TyCoRep\r\n checkValidSubst, called at compiler/types/TyCoRep.hs:2121:29 in ghc:TyCoRep\r\n substTy, called at compiler/coreSyn/CoreArity.hs:1197:19 in ghc:CoreArity\r\n Call stack:\r\n CallStack (from HasCallStack):\r\n prettyCurrentCallStack, called at compiler/utils/Outputable.hs:1133:58 in ghc:Outputable\r\n callStackDoc, called at compiler/utils/Outputable.hs:1137:37 in ghc:Outputable\r\n pprPanic, called at compiler/utils/Outputable.hs:1186:5 in ghc:Outputable\r\n assertPprPanic, called at compiler/types/TyCoRep.hs:2088:56 in ghc:TyCoRep\r\n checkValidSubst, called at compiler/types/TyCoRep.hs:2121:29 in ghc:TyCoRep\r\n substTy, called at compiler/coreSyn/CoreArity.hs:1197:19 in ghc:CoreArity\r\n\r\nPlease report this as a GHC bug: http://www.haskell.org/ghc/reportabug\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue