A `a` -> `id a` transformation does not preserve "it type-checks"
Summary
I am trying to write a ghc plugin for code coverage: See the plan here: https://github.com/NorfairKing/dekking#source-to-source-transformation
Replacing every expression a
by id a
produces code that does not type-check.
Steps to reproduce
Examples (using servant-server-19.2
:
This type-checks:
hoistExampleServer :: Server EmptyAPI
hoistExampleServer = hoistServerWithContext (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
This does not:
hoistExampleServer :: Server EmptyAPI
hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
This is the error (with GHC 9.0.2):
src/ServantExample.hs:47:26: error:
• Couldn't match type: forall x. m0 x -> Handler x
with: a0 -> a0
Expected: Proxy EmptyAPI
-> Proxy '[]
-> (a0 -> a0)
-> Tagged m0 EmptyServer
-> Tagged Handler EmptyServer
Actual: Proxy EmptyAPI
-> Proxy '[]
-> (forall x. m0 x -> Handler x)
-> ServerT EmptyAPI m0
-> ServerT EmptyAPI Handler
• In the first argument of ‘id’, namely ‘hoistServerWithContext’
In the expression:
(id hoistServerWithContext)
(Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
In an equation for ‘hoistExampleServer’:
hoistExampleServer
= (id hoistServerWithContext)
(Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
|
47 | hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
This is the error (with GHC 9.2.4):
src/ServantExample.hs:47:26: error:
• Couldn't match expected type: forall x. m0 x -> Handler x
with actual type: a0 -> a0
• In the first argument of ‘id’, namely ‘hoistServerWithContext’
In the expression:
(id hoistServerWithContext)
(Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
In an equation for ‘hoistExampleServer’:
hoistExampleServer
= (id hoistServerWithContext)
(Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
|
47 | hoistExampleServer = (id hoistServerWithContext) (Proxy :: Proxy EmptyAPI) (Proxy :: Proxy '[]) id emptyServer
| ^^^^^^^^^^^^^^^^^^^^^^
Even with ImpredicateTypes
and DeepSubsumption
, this does not compile.
Expected behavior
GHC should accept this (I think).
Environment
- GHC version used: GHC 9.0.2 and GHC 9.2.4
Optional:
- Operating System: NixOS
- System Architecture: x86_64-linux