Back to Scala3

E122: Imported Twice

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

3.8.41.2 KB
Original Source

E122: Imported Twice

This error is emitted when the same name is imported twice on the same import line.

Each import line should only import a name once. Duplicate imports on the same line are redundant and indicate a likely mistake.


Example

scala
import scala.collection.mutable.{ArrayBuffer, ArrayBuffer}

Error

scala
-- [E122] Syntax Error: example.scala:1:46 -------------------------------------
1 |import scala.collection.mutable.{ArrayBuffer, ArrayBuffer}
  |                                              ^^^^^^^^^^^
  |                    ArrayBuffer is imported twice on the same import line.

Solution

scala
// Import each name only once
import scala.collection.mutable.ArrayBuffer
scala
// Or if you need aliases, use different names
import scala.collection.mutable.{ArrayBuffer, ArrayBuffer as MutableBuffer}
<!-- 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>