Clean up the inferred type variable restriction
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. SeeNote [Unobservably inferred type variables]
inGHC.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
intoGHC.Rename.Utils
(under the new namenoNestedForallsContextsErr
), since it now needs to be invoked from multiple modules. I also added a helper functionaddNoNestedForallsContextsErr
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 nestedforall
s, I now invokeaddNoNestedForallsContextsErr
when renamingSPECIALISE 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.