Skip to content

Confusing 'permanently hidden' import warning #8808

@scabug

Description

@scabug

When an import adds in scope an object with the same name as a class defined in the package, the imported SomeClass' is permanently hidden by ...` warning makes it look like the import statement is not useful. When in fact it might be used to access the elements of the object.

The warning appears with the following files, and the code doesn't compile anymore if the import is removed.

// anotherpackage/SomeClass.scala
package anotherpackage

object SomeClass {
  val CONST= 1
}
// apackage/ScalaClass.scala
package apackage

import anotherpackage.SomeClass  // permanently hidden warning here

class ScalaClass {
  val i = SomeClass.CONST  // error if the import is removed
}

class SomeClass {

}

To be fair, the warning states that the class is hidden, not the object.

The only way to have code that compiles without warning is to use an import rename.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions