Skip to content

An implicit val should not be available for defining itself? #6114

Closed
@liufengyun

Description

@liufengyun

The following code compiles in Scalac 2.12. However, if we give explicit type to x, it compiles neither in Scalac nor Dotty.

class Test {
  implicit val m: Int = 10
  def get(implicit x: Int): Int = ???
  def bar: Unit = {
    implicit val x = get
    // implicit val x: Int = get
  }
}

Error message:

5 |    implicit val x: Int = get
  |                             ^
  |               x is a forward reference extending over the definition of x

Such code exists in ScalaTest:

implicit val strEq = StringNormalizations.lowerCased.toEquality
es.contains("one") shouldBe true;
es.contains("ONE") shouldBe false

trait NormalizingEquality[A] extends Equality[A]

trait Uniformity[A] extends Normalization[A] {
    final def toEquality(implicit equality: Equality[A]): NormalizingEquality[A] = ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions