Back to Scala3

E036: Dangling This In Path

docs/_docs/reference/error-codes/E036.md

3.8.41.3 KB
Original Source

E036: Dangling This In Path

Note: This error was removed before Scala 3.0.0 was released and was never emitted by the Scala 3 compiler.

What it did

This error was triggered when using this at the end of an import path or type selection without selecting a member.

Example

scala
trait Outer {
  val member: Int
  type Member
  trait Inner {
    import Outer.this
  }
}

Error

scala
-- [E036] Syntax Error: example.scala:5:11 -------------------------------------
5 |    import Outer.this
  |           ^^^^^^^^^^
  |           Expected an additional member selection after the keyword `this`

Explanation

Paths of imports and type selections must not end with the keyword this. The compiler expected an additional member selection after this.

Valid usages required selecting a member:

scala
trait Outer {
  val member: Int
  type Member
  trait Inner {
    // Valid: selecting a member after this
    import Outer.this.member

    // Valid: type selection
    type T = Outer.this.Member
  }
}
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>