Back to Scala3

E033: Package Duplicate Symbol

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

3.8.41.6 KB
Original Source

E033: Package Duplicate Symbol

This error is emitted when you try to define a nested package with the same name as an existing type (class or trait) in the same parent package.

Package names must be unique and cannot conflict with type definitions in the same scope.

Note: This error requires package statements which cannot be demonstrated in Scaladoc's snippet compiler. The examples below show the code structure but are not compiled.


Example

scala
package foo:
  trait id:
    def bar: Int

package foo:
  package id:  // error: Trying to define package with same name as trait id
    class Bar

Error

scala
-- [E033] Naming Error: example.scala:6:10 -------------------------------------
6 |  package id:  // error: Trying to define package with same name as trait id
  |          ^^
  |          Trying to define package with same name as trait id

Solution

Use a different package name to avoid conflict with the type:

scala
// Use a different package name
package foo:
  trait id:
    def bar: Int

package foo:
  package idPkg:
    class Bar

Or rename the trait to avoid conflict:

scala
// Or rename the trait to avoid conflict
package foo:
  trait IdTrait:
    def bar: Int

package foo:
  package id:
    class Bar
<!-- 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>