type signature code lens required vs provided constraints #1951
Labels
component: ghcide-type-lenses
type: bug
Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
The TypeLens plugin tries to produce code lenses suggesting type signatures for pattern synonyms like:
But it's not doing the right thing to get the type. See ghcide/src/Development/IDE/Plugin/TypeLenses.hs line 283.
safeTyThingType returns Nothing for unidirectional pattern synonyms. It is trying to get the type of the "builder" function. But a unidirectional pattern synonym doesn't have one. So this causes the type lens plugin to crash:
E.g.:
LSP logs stderr:
But even for pattern synonyms that do have builders, that's still not the type we want. Consider this next example from the GHC docs:
https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pattern_synonyms.html#typing-of-pattern-synonyms
The code-lens plugin suggests
as the type signature for ExNumPat2. This is the wrong type, and it will not typecheck. The right type is the one shown on ExNumPat1.
For pattern synonyms, the first (Num a, Eq a) => is the constraints required to use the pattern. The second (Show b) => is the constraints provided in the body of the match. My understanding is that this means that pattern synonyms types can't actually fit in the datatype Type.
The "matchers" associated with type synonyms have types of their own, but we don't want those either.
Here are some comparisons:
Your environment
Ubuntu
emacs
The text was updated successfully, but these errors were encountered: