Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear type error when HasType constraint is missing #122

Open
f-f opened this issue May 26, 2020 · 0 comments
Open

Unclear type error when HasType constraint is missing #122

f-f opened this issue May 26, 2020 · 0 comments

Comments

@f-f
Copy link

f-f commented May 26, 2020

Thanks for the great talk today 🙂

I found that when calling the/typed on a type that is missing the HasType constraint - e.g. when wiring up some code using a Reader and using this library for pulling values from there - produces less-than-desiderable type errors.

Minimal repro:

foo :: env -> Int
foo env = env ^. the @Int

..which produces this type error:

error:
    • Overlapping instances for HasType Int env
        arising from a use of ‘the’
      Matching instances:
        instance generic-lens-core-2.0.0.0:Data.Generics.Product.Internal.Typed.Context
                   a s =>
                 HasType a s
          -- Defined in ‘Data.Generics.Product.Typed’
        instance [overlapping] HasType a a
          -- Defined in ‘Data.Generics.Product.Typed’
        ...plus one instance involving out-of-scope types
        (use -fprint-potential-instances to see them all)
      (The choice depends on the instantiation of ‘env’
       To pick the first instance above, use IncoherentInstances
       when compiling the other instance declarations)
    • In the second argument of ‘(^.)’, namely ‘the @Int’
      In the expression: env ^. the @Int
      In an equation for ‘foo’: foo env = env ^. the @Int

I would expect this to be:

  • about "missing constraint" instead of "overlapping instance"
  • a bit more actionable - e.g. I'd at least like GHC to suggest me to add the HasType constraint to the env, as it usually happens when trying to use a typeclass method on something that doesn't have the constraint.

Is there anything we could do about this here, or is this an inherent GHC limitation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant