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

Regression 2.13: implicit resolution #11765

Open
japgolly opened this issue Oct 9, 2019 · 7 comments

Comments

@japgolly
Copy link

commented Oct 9, 2019

The following code works in 2.12.x but fails to compile on 2.13.1:

object Blah {

  trait TC[F[_]]

  final class Ops[F[_], A](m: F[A])(implicit p: TC[F]) {
    def example = 0
  }

  implicit def toTcOps[F[_], A](fa: F[A])(implicit tc: TC[F]): Ops[F, A] =
    new Ops[F, A](fa)(tc)

  final case class X[A]()

  implicit val tcX: TC[X] =
    new TC[X] {}

  object Example1 {
    type Y[A, B] = X[(A, B)] // both arguments used

    def woah[A, B](a: Y[A, B]) = {
      a.example                      // Error in 2.13 but ok in 2.12
      toTcOps(a).example             // Error in 2.13 but ok in 2.12
      toTcOps[X, (A, B)](a).example  // OK in 2.13 & 2.12
    }
  }

  object Example2 {
    type Y[A, B] = X[A] // phantom type

    def woah[A, B](a: Y[A, B]) = {
      a.example                 // Error in 2.13 but ok in 2.12
      toTcOps(a).example        // Error in 2.13 but ok in 2.12
      toTcOps[X, A](a).example  // OK in 2.13 & 2.12
    }
  }

}

Error:

[error] Blah.scala:21:9: value example is not a member of Blah.Example1.Y[A,B]
[error]       a.example                 // Error in 2.13 but ok in 2.12
[error]         ^
[error] Blah.scala:22:14: could not find implicit value for parameter tc: Blah.TC[[B]Blah.Example1.Y[A,B]]
[error]       toTcOps(a).example        // Error in 2.13 but ok in 2.12
[error]              ^
[error] Blah.scala:31:9: value example is not a member of Blah.Example2.Y[A,B]
[error]       a.example                 // Error in 2.13 but ok in 2.12
[error]         ^
[error] Blah.scala:32:14: could not find implicit value for parameter tc: Blah.TC[[B]Blah.Example2.Y[A,B]]
[error]       toTcOps(a).example        // Error in 2.13 but ok in 2.12
[error]              ^
[error] four errors found

@joroKr21

This comment has been minimized.

Copy link

commented Oct 9, 2019

The examples also fail on 2.12.10 with -Ypartial-unification which is unconditional in 2.13

@japgolly

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

Thanks @joroKr21 , I forgot to mention that I have -Ypartial-unification on for 2.12 😁

@japgolly

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

Hmm I just tried with on 2.12.10 without -Ypartial-unification and it compiles.

> scala  
Welcome to Scala 2.12.10 (OpenJDK 64-Bit GraalVM CE 19.2.0, Java 1.8.0_222).
Type in expressions for evaluation. Or try :help.

scala> object Blah {
     | 
     |   trait TC[F[_]]
     | 
     |   final class Ops[F[_], A](m: F[A])(implicit p: TC[F]) {
     |     def example = 0
     |   }
     | 
     |   implicit def toTcOps[F[_], A](fa: F[A])(implicit tc: TC[F]): Ops[F, A] =
     |     new Ops[F, A](fa)(tc)
     | 
     |   final case class X[A]()
     | 
     |   implicit val tcX: TC[X] =
     |     new TC[X] {}
     | 
     |   object Example1 {
     |     type Y[A, B] = X[(A, B)] // both arguments used
     | 
     |     def woah[A, B](a: Y[A, B]) = {
     |       a.example                      // Error in 2.13 but ok in 2.12
     |       toTcOps(a).example             // Error in 2.13 but ok in 2.12
     |       toTcOps[X, (A, B)](a).example  // OK in 2.13 & 2.12
     |     }
     |   }
     | 
     |   object Example2 {
     |     type Y[A, B] = X[A] // phantom type
     | 
     |     def woah[A, B](a: Y[A, B]) = {
     |       a.example                 // Error in 2.13 but ok in 2.12
     |       toTcOps(a).example        // Error in 2.13 but ok in 2.12
     |       toTcOps[X, A](a).example  // OK in 2.13 & 2.12
     |     }
     |   }
     | 
     | }
<console>:13: warning: higher-kinded type should be enabled
by making the implicit value scala.language.higherKinds visible.
This can be achieved by adding the import clause 'import scala.language.higherKinds'
or by setting the compiler option -language:higherKinds.
See the Scaladoc for value scala.language.higherKinds for a discussion
why the feature should be explicitly enabled.
         trait TC[F[_]]
                  ^
<console>:15: warning: higher-kinded type should be enabled
by making the implicit value scala.language.higherKinds visible.
         final class Ops[F[_], A](m: F[A])(implicit p: TC[F]) {
                         ^
<console>:19: warning: higher-kinded type should be enabled
by making the implicit value scala.language.higherKinds visible.
         implicit def toTcOps[F[_], A](fa: F[A])(implicit tc: TC[F]): Ops[F, A] =
                              ^
<console>:19: warning: implicit conversion method toTcOps should be enabled
by making the implicit value scala.language.implicitConversions visible.
This can be achieved by adding the import clause 'import scala.language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scaladoc for value scala.language.implicitConversions for a discussion
why the feature should be explicitly enabled.
         implicit def toTcOps[F[_], A](fa: F[A])(implicit tc: TC[F]): Ops[F, A] =
                      ^
defined object Blah
@japgolly

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

I also tried it on the following and it compiles successfully without -Ypartial-unification:

  • 2.12.2
  • 2.12.3
  • 2.12.4
  • 2.12.8
  • 2.12.10
@joroKr21

This comment has been minimized.

Copy link

commented Oct 9, 2019

Yes I meant that it fails with -Ypartial-unification on, i.e. it's the result of partial unifcation.
Because the compiler will accept Y[A, *] instead of searching in the supertypes and finding X.

@SethTisue

This comment has been minimized.

Copy link
Member

commented Oct 9, 2019

@milessabin ring a bell?

@milessabin

This comment has been minimized.

Copy link

commented Oct 11, 2019

I think that @joroKr21 has diagnosed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.