bug
bug copied to clipboard
Type inference affects on implicit parameters inside traits?
reproduction steps
This is a short example:
import scala.concurrent._
trait TestModule {
implicit val ec: ExecutionContext
}
class ClassA()(implicit ec: ExecutionContext) {}
trait Trait1 {
this: TestModule =>
implicit val ec: ExecutionContext
lazy val a: ClassA = new ClassA()
}
It compiles fine until you remove an explicit type declaration in the last line:
lazy val a = new ClassA()
and now it starts complaining about implicit parameters (ExecutionContext in this example).
Behaviour presents on Scala 2.13.4 / 2.12.12
But not on dotty/Scala 3, so might be fixed there.
problem
Unclear behaviour either of type inference or implicit resolution.
There are different ways to make it compile, another way is removing duplicate implicit val ec: ExecutionContext but why it behaves like this unclear. Not sure if this was reported before or expected behaviour.