5

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]       ^
emchristiansen
  • 3,550
  • 3
  • 26
  • 40

1 Answers1

1

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

Dia Kharrat
  • 5,948
  • 3
  • 32
  • 43