Back to Scala3

E185: Unimported and Imported

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

3.8.41.4 KB
Original Source

E185: Unimported and Imported

This error occurs when the same identifier is both imported and unimported (or unimported twice) on the same import line.

In Scala 3, you can selectively unimport members using as _ syntax. However, it doesn't make sense to both import and unimport the same identifier on the same line, as this represents contradictory intentions.


Example

scala
object MyLib:
  val value = 42

import MyLib.{value, value as _}

Error

scala
-- [E185] Syntax Error: example.scala:4:21 -------------------------------------
4 |import MyLib.{value, value as _}
  |                     ^^^^^
  |                 value is unimported and imported on the same import line.

Solution

Choose either to import or unimport the identifier:

scala
object MyLib:
  val value = 42

// Either import it:
import MyLib.value

def example(): Int = value

Or unimport it if you want to exclude it from a wildcard import:

scala
object MyLib:
  val value = 42
  val other = 100

// Unimport value, import everything else:
import MyLib.{value as _, *}

def example(): Int = other
<!-- 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>