Scala Could not find implicit value supplied by mixin

Viewed 56

Using Scala version 2.11.12.

I can't seem to make the implicit config supplied by the mixin Foundation trait visible to the Path class' constructor.

case class Config() {
  val content = "hello"
}

trait Foundation {
  implicit val config: Config = Config()
}

trait PathBase {
  def somePath: String = "/user/xxx"
}

class Path(implicit val config: Config) extends PathBase {
  def someOtherPath: String = "/user/yyy"
}

trait NavigatorBase {
  protected implicit val hdfs: PathBase
}

trait Navigator extends NavigatorBase with Foundation {
//  private implicit val config1: Config = config
  protected implicit val hdfs = new Path
}

The above code raises the following error:

:39: error: could not find implicit value for parameter config: Config protected implicit val hdfs = new Path

However, if I define a new implicit val using the config supplied by Foundation before calling Path's constructor (see the commented line in the code), the code works. If I write trait Navigator extends Foundation without mixing in NavigatorBase, the code also works.

Is there a way to make the implicit config visible to Path's constructor without having to define a new implicit variable or remove the extension of NavigatorBase?

1 Answers
Related