• Ryan Scott's avatar
    Tweak error messages for narrowly-kinded assoc default decls · 33b0a291
    Ryan Scott authored
    This program, from #13971, currently has a rather confusing error
    message:
    
    ```hs
    class C a where
      type T a :: k
      type T a = Int
    ```
    ```
        • Kind mis-match on LHS of default declaration for ‘T’
        • In the default type instance declaration for ‘T’
          In the class declaration for ‘C’
    ```
    
    It's not at all obvious why GHC is complaining about the LHS until
    you realize that the default, when printed with
    `-fprint-explicit-kinds`, is actually `type T @{k} @* a = Int`.
    That is to say, the kind of `a` is being instantiated to `Type`,
    whereas it ought to be a kind variable. The primary thrust of this
    patch is to weak the error message to make this connection
    more obvious:
    
    ```
        • Illegal argument ‘*’ in:
            ‘type T @{k} @* a = Int’
            The arguments to ‘T’ must all be type variables
        • In the default type instance declaration for ‘T’
          In the class declaration for ‘C’
    ```
    
    Along the way, I performed some code cleanup suggested by @rae in
    ghc/ghc#13971 (comment 191287). Before,
    we were creating a substitution from the default declaration's type
    variables to the type family tycon's type variables by way of
    `tcMatchTys`. But this is overkill, since we already know (from the
    aforementioned validity checking) that all the arguments in a default
    declaration must be type variables anyway. Therefore, creating the
    substitution is as simple as using `zipTvSubst`. I took the
    opportunity to perform this refactoring while I was in town.
    
    Fixes #13971.
    33b0a291
Name
Last commit
Last update
.circleci Loading commit data...
.gitlab Loading commit data...
bindisttest Loading commit data...
compiler Loading commit data...
distrib Loading commit data...
docs Loading commit data...
driver Loading commit data...
ghc Loading commit data...
hadrian Loading commit data...
includes Loading commit data...
libffi Loading commit data...
libffi-tarballs @ 96d02800 Loading commit data...
libraries Loading commit data...
mk Loading commit data...
nofib @ 7a702cc1 Loading commit data...
rts Loading commit data...
rules Loading commit data...
testsuite Loading commit data...
utils Loading commit data...
.appveyor.sh Loading commit data...
.ghcid Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.gitmodules Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
ANNOUNCE Loading commit data...
CODEOWNERS Loading commit data...
HACKING.md Loading commit data...
INSTALL.md Loading commit data...
LICENSE Loading commit data...
MAKEHELP.md Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
Vagrantfile Loading commit data...
aclocal.m4 Loading commit data...
appveyor.yml Loading commit data...
boot Loading commit data...
build.nix.sh Loading commit data...
config.guess Loading commit data...
config.sub Loading commit data...
configure.ac Loading commit data...
ghc.mk Loading commit data...
install-sh Loading commit data...
llvm-passes Loading commit data...
llvm-targets Loading commit data...
packages Loading commit data...
settings.in Loading commit data...
validate Loading commit data...