Skip to content

Type inference affects on implicit parameters inside traits? #12351

@abdolence

Description

@abdolence

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)implicitinfer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions