Skip to content

Clean up the inferred type variable restriction

Ryan Scott requested to merge wip/T18432-T18455 into master

This patch primarily:

  • Documents check_inferred_vars more carefully. This is the function which throws an error message if a user quantifies an inferred type variable in a place where specificity cannot be observed. See Note [Unobservably inferred type variables] in GHC.Rename.HsType.
  • Removes the inferred type variable restriction for default method type signatures, per the discussion in #18432 (closed). As a result, this patch fixes #18432 (closed).

Along the way, I performed some various cleanup:

  • I moved no_nested_foralls_contexts_err into GHC.Rename.Utils (under the new name noNestedForallsContextsErr), since it now needs to be invoked from multiple modules. I also added a helper function addNoNestedForallsContextsErr that throws the error message after producing it, as this is a common idiom.
  • In order to ensure that users cannot sneak inferred type variables into SPECIALISE instance pragmas by way of nested foralls, I now invoke addNoNestedForallsContextsErr when renaming SPECIALISE instance pragmas, much like when we rename normal instance declarations. (This probably should have originally been done as a part of the fix for #18240 (closed), but this task was somehow overlooked.) As a result, this patch fixes #18455 (closed) as a side effect.

Merge request reports