Writing GHC plugin to modify AST despite failure to type-check
Zubin Duggal
zubin at well-typed.com
Thu Jul 1 08:24:00 UTC 2021
You could set `-fdefer-type-errors` on the file, possibly using
`dynflagsPlugin`. This will give your `typeCheckResultAction` an AST
with all nodes containing type errors wrapped in an `evDelayedError`
term. See Note [Deferring coercion errors to runtime] for more details.
You can walk through the AST and replace these wrappers with `liftIO`
(with the correct type and dictionary arguments) and things should
work as you want.
Of course, this will defer all type errors in the program, not just the
ones that your plugin can solve. You could work around this by setting
`log_action` to "upgrade" any type error warnings you didn't handle and
arose as a result of `Reason Opt_DeferTypeErrors :: WarnReason` back to
proper errors.
More information about the ghc-devs
mailing list