Reputation: 4486
I'm working on a compiler plugin that should abort compilation if a declaration doesn't have a type that given as a plugin argument.
I think the function Unify.tcMatchTy :: Type -> Type -> Maybe TCvSubstS
would do the trick. I can find one of the argument types from the inputs of the typechecker plugin, but the other comes in as a plugin argument. That is, as a String
.
How do I, in a typechecker plugin, get a Type
from a String
? I tried using parseType
followed by calls to rnHsType
and tcLHsType
, which does convert a String
into Type
. This seems to work for simple types, but it results in this kind of error when the string contains a type variable:
Text:0:0: error: Not in scope: type variable ‘a’
Text:0:0: error:
• GHC internal error: ‘a’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: []
• In the type ‘a -> b’
I'm probably missing some bit (or perhaps a huge chunk) of work here, but where should I look for it?
(Prefixing the input with a forall a b.
caused a compiler panic)
Upvotes: 2
Views: 63