Skip to content

Constructor parameter shadows parent implicit val #18135

Closed
@dwijnand

Description

@dwijnand

Compiler version

3.3.0, 3.3.1-RC, 3.3.2-RC1-bin-20230703-0a21ecf-NIGHTLY-git-0a21ecf

Minimized code

class Conf

class Bar(_conf: Conf) {
  implicit val conf: Conf = _conf
}

class Foo(conf: Conf) extends Bar(conf)
//class Foo(_conf: Conf) extends Bar(_conf)
// using a different name fixes it

class Test {
  def test(foo: Foo) = {
    import foo._
    //implicit val conf: Conf = foo.conf
    // manually redefining it also fixes it
    assert(conf != null)
    assert(implicitly[Conf] != null)
  }
}

Output

-- [E006] Not Found Error: Test.scala:14:11 ------------------------------------
14 |    assert(conf != null)
   |           ^^^^
   |           Not found: conf
   |
   | longer explanation available when compiling with `-explain`
-- [E172] Type Error: Test.scala:15:27 -----------------------------------------
15 |    assert(implicitly[Conf] != null)
   |                           ^
   |No given instance of type Conf was found for parameter e of method implicitly in object Predef
2 errors found

Expectation

I expect it to compile cleanly, like it does in Scala 2.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions