emchristiansen
emchristiansen

Reputation: 3602

Possible bug with Scala 2.10.2 implicits

I'm getting unexpected behavior with Scala implicit resolution, and I'd like to know whether the bug is in my understanding or in the Scala compiler. Here's the code:

trait Trait1[A]

implicit def trait1ToList[A](trait1: Trait1[A]): List[A] = ???

trait Trait2[C]

{
  implicit def trait2Implicit[A, C <% List[A]]: Trait2[C] = ???

  // Compiles, as expected.
  implicitly[Trait2[Trait1[Int]]]
}

{
  implicit def trait2Pimp[A, C <% List[A]](int: Int): Trait2[C] = ???

  // Compiles, as expected.
  implicitly[Int => Trait2[Trait1[Int]]]

  // Does not compile, which is unexpected.
  // This is weird, because the fact the previous line compiles
  // implies the implicit conversion is in scope.
  2: Trait2[Trait1[Int]]
}

The compilation error is:

[error] /Users/eric/Dropbox/t/2013_q1/billy/src/test/scala/billy/experiments/wideBaseline/testWideBaselineExperiment.scala:56: No implicit view available from Trait1[Int] => List[A].
[error]       2: Trait2[Trait1[Int]]
[error]       ^

Upvotes: 5

Views: 154

Answers (1)

Dia Kharrat
Dia Kharrat

Reputation: 6006

Yes, this was a bug in the scala compiler that has since been fixed in 2.11.

Upvotes: 1

Related Questions