Skip to content

Closure for implicit function inferring wrong type  #2671

Closed
@nicolasstucki

Description

@nicolasstucki
object Foo {

  def map[E](f: implicit E => Int): (implicit E => Int) = ???

  implicit def i: Int = ???

  def f: implicit Int => Int = ???

  val a: Int = map(f)

}
10 |  val a:  Int = map(f)
   |                      ^
   |no implicit argument of type Nothing found for parameter x$0 of method apply in trait ImplicitFunction1

result of tests/neg/foo.scala after frontend:

package <empty> {
  final lazy module val Foo: Foo$ = new Foo$()
  final module class Foo$() extends Object() { this: Foo.type => 
    def map[E](f: ImplicitFunction1[E, Int]): ImplicitFunction1[E, Int] = 
      {
        def $anonfun(implicit evidence$1: E): Int = ???
        closure($anonfun)
      }
    implicit def i: Int = ???
    def f: ImplicitFunction1[Int, Int] = 
      {
        def $anonfun(implicit evidence$2: Int): Int = ???
        closure($anonfun)
      }
    val a: Int = 
      Foo.map[Nothing^](
        {
          def $anonfun(implicit evidence$3: Nothing): Int = 
            Foo.f.apply(evidence$3)
          closure($anonfun)
        }
      ).Int
  }
}

Note the def $anonfun(implicit evidence$3: Nothing): Int = where we should have inferred evidence$3: Int because of the type of f.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions