Skip to content

Inference issue when an implicit method is promoted to an implicit function #4725

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

Closed
kubukoz opened this issue Jun 26, 2018 · 0 comments
Closed

Comments

@kubukoz
Copy link
Contributor

kubukoz commented Jun 26, 2018

import language.higherKinds

object Main {
  trait Eq[A]  
  
  case class Cofree[S[_], A](head: A, tail: Cofree[S, A]) //simplified
  

  implicit val intEq: Eq[Int] = null
  implicit def forList[A : Eq]: Eq[List[A]] = ???
  
  
  implicit def eqCofree[S[_], A : Eq](implicit
    S: implicit Eq[A] => Eq[S[A]]): Eq[Cofree[S, A]] = ???
  
  
  val a = eqCofree[List, Int]
}

This fails with:

-- Error: /tmp/scastie6251223766744740367/src/main/scala/main.scala:16:29 ------
16 |  val a = eqCofree[List, Int]
   |                             ^
   |no implicit argument of type implicit Main.Eq[Int] => Main.Eq[List[Int]] was found for parameter S of method eqCofree in object Main.
   |I found:
   |
   |    {
   |      def $anonfun(implicit evidence$4: Main.Eq[Int]): Main.Eq[List[Int]] = 
   |        {
   |          def $anonfun(evidence$1: Main.Eq[Any]): Main.Eq[List[Any]] = 
   |            Main.forList[Any](evidence$1)
   |          closure($anonfun)
   |        }
   |      closure($anonfun)
   |    }
   |
   |But method forList in object Main does not match type implicit Main.Eq[Int] => Main.Eq[List[Int]]

but if you use eqCofree(intEq, forList), it compiles.

odersky added a commit that referenced this issue Jul 25, 2018
Fix #4725: Expand implicit method to implicit func
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