Skip to content

Mask root import #17674

Closed
Closed
@som-snytt

Description

@som-snytt
import _root_.{jdk => _}

object Test extends App {
  import jdk.CollectionConverters._
  val xs = java.util.List.of(42)
  println(xs.asScala)
}

Currently, we can only mask a root context that is a "predef" object.

It would be nice to also mask an arbitrary package introduced by a root context, such as import _root_.java as _.

It would be even nicer to mask rooted packages from the class path.

Unfortunately, rooted packages are not currently modeled as root contexts per se.

#14781 (comment)

In that sense, there is an impedance mismatch between this syntax and the "mental model" for rooted packages. But it's just syntax.

Also, note that predef is not an import: it competes at level 4 precedence.

I don't know whether users commonly mask predef, where you'd normally ask for -Yno-imports or whatever, but it seems healthy to provide another tool in controlling the "global" namespace, which can be polluted by anything on the class path.

Currently, it's possible to specify a root for hygienic purposes, but not exclude it for convenience.

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