Closed
Description
reproduction steps
using Scala 2.13.6,
trait Companion[T]
abstract class Service[T: Companion]
object Foo {
// can't find required implicit
class Impl extends Service[String]
implicit object Impl extends Companion[String]
}
problem
I'm expecting the above code to compile but it doesn't. If I (1) add dummy line that calls for this implicit value too, or (2) change the definition order, or (3) change implicit object
to implicit lazy val
then the code compiles fine
1.
trait Companion[T]
abstract class Service[T: Companion]
object Foo {
def unused: Any = implicitly[Impl.type]
class Impl extends Service[String]
implicit object Impl extends Companion[String]
}
trait Companion[T]
abstract class Service[T: Companion]
object Foo {
implicit object Impl extends Companion[String]
class Impl extends Service[String]
}
trait Companion[T]
abstract class Service[T: Companion]
object Foo {
class Impl extends Service[String]
implicit lazy val Impl: Companion[String] = ???
}
I'm really surprized that (1) fixes this issue. Intuitively it should not affect implicit resolution of existing code at all.
Initially I've faced this issue on Scala 2.12.14 which has exactly the same behavior in this case. Also, if I compile this code in Scala 3 then it works fine. Maybe you will find it useful.
Metadata
Metadata
Assignees
Labels
No labels