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

Type class instance for type alias in package object isn't found #8048

Closed
travisbrown opened this issue Jan 21, 2020 · 1 comment
Closed

Comments

@travisbrown
Copy link
Contributor

minimized code

package tc {
  trait Functor[F[_]]
}

package object tc {
  trait Foo[A]
  type Id[A] = A

  implicit val fooFunctor: Functor[Foo] = new Functor[Foo] {}
  implicit val idFunctor: Functor[Id] = new Functor[Id] {}
}

package test {
  object Test {
    val functor1 = implicitly[tc.Functor[tc.Foo]]
    val functor2 = implicitly[tc.Functor[tc.Id]]
  }
}
Compilation output
-- Error: Id.scala:16:48 -------------------------------------------------------
16 |    val functor2 = implicitly[tc.Functor[tc.Id]]
   |                                                ^
   |no implicit argument of type tc.Functor[tc.Id] was found for parameter ev of method implicitly in object DottyPredef
   |
   |The following import might fix the problem:
   |
   |  import tc.idFunctor
   |         
1 error found

expectation

This compiles fine on Scala 2, and we rely on that extensively in Cats. Importing tc._ or tc.idFunctor is a workaround, but not really very pleasant for our case.

If you move the definitions in the package object directly into package tc, neither val in Test compiles.

@odersky
Copy link
Contributor

odersky commented Jan 21, 2020

That one is also intentional. See point 3 of https://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html. Package prefixes are no longer part of the implicit scope of a type. I believe with the import suggestions the breakage should be manageable.

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

No branches or pull requests

2 participants