bug icon indicating copy to clipboard operation
bug copied to clipboard

method argument not used for prefix of implicit argument

Open scabug opened this issue 12 years ago • 2 comments

class Cake {
  trait Foo[T]
  object Foo {
    // if FooString is replaced with fooString, everything works
    // implicit val fooString = new Foo[String] {}
    implicit object FooString extends Foo[String]
  }
  def foo[T: Foo](x: T) = x
}

object Test extends App {
  def foo(c: Cake) = {
    // doesn't work: c.foo("1")
    // Test.scala:11: error: could not find implicit value for evidence parameter of type c.Foo[String]
    // c.foo("1")

    // this works
    val c1 = c
    c1.foo("1")
  }
}

scabug avatar Dec 29 '12 13:12 scabug

Imported From: https://issues.scala-lang.org/browse/SI-6892?orig=1 Reporter: @xeno-by

scabug avatar Dec 29 '12 13:12 scabug

@adriaanm said (edited on May 16, 2014 10:54:55 AM UTC): I suspect the argument c of def foo is somehow considered not in scope when typing FooString.

This works:

def foo(c: Cake): Unit = { 
  implicit val ev: c.Foo[String] /*return type crucial*/= c.Foo.FooString
  c.foo("1")
}

scabug avatar May 16 '14 10:05 scabug