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

Implicit resolution regression in 2.13.x #11068

Closed
Atry opened this issue Aug 11, 2018 · 8 comments
Closed

Implicit resolution regression in 2.13.x #11068

Atry opened this issue Aug 11, 2018 · 8 comments

Comments

@Atry
Copy link

Atry commented Aug 11, 2018

import scala.language.higherKinds
import scala.concurrent.Future

object Regression {
  
  trait Functor[F[_]]
  trait Monad[F[_]] extends Functor[F]
  trait MonadError[F[_], E] extends Monad[F]
  implicit def futureMonad: Monad[Future] = ???
  
  

  object OptionT extends OptionTInstances0 {
    implicit final def OptionTFunctor[F[_]](implicit F0: Functor[F]): Functor[({type T[A] = OptionT[F, A]})#T] = ???

  }

  sealed abstract class OptionTInstances0 {
    implicit final def OptionTMonadError[F[_]](implicit F0: Monad[F]): MonadError[({type T[A] = OptionT[F, A]})#T, Throwable] = ???

  }

  trait OptionT[F[_], A]

  def main(args: Array[String]): Unit = {

    def f = implicitly[Functor[({type T[A] = OptionT[Future, A]})#T]]

  }

}
@SethTisue
Copy link
Member

is it reproducible without outside dependencies?

@Atry
Copy link
Author

Atry commented Aug 11, 2018

The example is updated to remove outside dependencies.

@xuwei-k
Copy link

xuwei-k commented Aug 12, 2018

compile success if swap these implicit def.

@@ -11,12 +11,12 @@
object Regression {
   
 
   object OptionT extends OptionTInstances0 {
-    implicit final def OptionTFunctor[F[_]](implicit F0: Functor[F]): Functor[({type T[A] = OptionT[F, A]})#T] = ???
+    implicit final def OptionTMonadError[F[_]](implicit F0: Monad[F]): MonadError[({type T[A] = OptionT[F, A]})#T, Throwable] = ???
 
   }
 
   sealed abstract class OptionTInstances0 {
-    implicit final def OptionTMonadError[F[_]](implicit F0: Monad[F]): MonadError[({type T[A] = OptionT[F, A]})#T, Throwable] = ???
+    implicit final def OptionTFunctor[F[_]](implicit F0: Functor[F]): Functor[({type T[A] = OptionT[F, A]})#T] = ???
 
   }

Some libraries encountered the same error (since Scala 2.13.0-M3)

@SethTisue SethTisue added this to the 2.13.0-RC1 milestone Aug 12, 2018
Atry added a commit to ThoughtWorksInc/tryt.scala that referenced this issue Aug 12, 2018
@xuwei-k
Copy link

xuwei-k commented Aug 12, 2018

scalaz/scalaz#1629

Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 13, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
Atry added a commit to ThoughtWorksInc/Dsl.scala that referenced this issue Aug 14, 2018
@joroKr21
Copy link
Member

MonadError is a subtype of Functor therefore this is not a bug but a bug fix! Granted, breaking change hence in 2.13

@barambani
Copy link

I think I ran into this as well. So I guess that the instance summoned by

implicitly[Functor[({type T[A] = OptionT[Future, A]})#T]]

will be MonadError, correct ?

@joroKr21
Copy link
Member

joroKr21 commented Oct 1, 2018

will be MonadError, correct ?

This example doesn't make much sense in practice. E.g. why would we say that OptionT has an instance of MonadError for Throwable? That seems wrong to me. Maybe for Unit, but how useful is that?

Anyway in this example, given that Future has a Monad instance then yes, MonadError will be selected as the Functor implementation.

@adriaanm
Copy link
Contributor

Closing since this is working as intended. Let us know if we should reopen.

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

6 participants