E083: Not A Path

This error is emitted when an expression is used where a stable path is required, but the expression is not an immutable path.

An immutable path is:

  • A reference to an immutable value (val), or
  • A reference to this, or
  • A selection of an immutable path with an immutable value

Paths are required in certain contexts like singleton types, type projections, and some pattern matches.


Example

var x = 1
def example: x.type = x

Error

-- [E083] Type Error: example.scala:2:13 ---------------------------------------
2 |def example: x.type = x
  |             ^^^^^^
  |(x : Int) is not a valid singleton type, since it is not an immutable path
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | An immutable path is
  |  - a reference to an immutable value, or
  |  - a reference to `this`, or
  |  - a selection of an immutable path with an immutable value.
   -----------------------------------------------------------------------------

Solution

// Use val instead of var for stable paths
val x = 1
def example: x.type = x
// Or don't use singleton types for mutable values
var x = 1
def example: Int = x