Skip to content

Constructor parameter shadows parent implicit val #18135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dwijnand opened this issue Jul 4, 2023 · 0 comments · Fixed by #18142
Closed

Constructor parameter shadows parent implicit val #18135

dwijnand opened this issue Jul 4, 2023 · 0 comments · Fixed by #18142
Assignees
Milestone

Comments

@dwijnand
Copy link
Member

dwijnand commented Jul 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment