Skip to content

REPL breakages importing from REPL artifacts or root imports (depending on version) #14781

Closed
@som-snytt

Description

@som-snytt

Minimized code

Welcome to Scala 3.1.1 (18, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> object sun { val x = 42 }
// defined object sun

scala> import sun.x
-- [E008] Not Found Error: ---------------------------------------------------------------------------------------------
1 |import sun.x
  |           ^
  |           value x is not a member of sun
1 error found

scala> import jdk.CollectionConverters.*
-- [E008] Not Found Error: ---------------------------------------------------------------------------------------------
1 |import jdk.CollectionConverters.*
  |       ^^^^^^^^^^^^^^^^^^^^^^^^
  |       value CollectionConverters is not a member of jdk
1 error found

scala> import _root_.
<empty>                 dotty                   javax                   org                     sun
<special-ops>           images                  jdk                     repl                    toolbarButtonGraphics
com                     java                    netscape                scala                   xsbti

or without REPL

import scala.jdk.CollectionConverters._
// not in Scala 2/3
//import jdk.CollectionConverters._
// in Scala 2
//scalac -Yimports:java,scala,scala.Predef,scala.jdk hh.scala
//import CollectionConverters._

object HelloWorld {
  def main(args: Array[String]) = {
    val ss = java.util.List.of("Hello", "world")
    println(ss.asScala.mkString("", ", ", "!"))
  }
}

Output

Random "root" symbols on the class path (see completions above) shadow things I actually care about.

Scala 2 is divided, in that REPL at least sees the sun and not its shadow:

Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.

scala> object sun { val x = 42 }
object sun

scala> import sun.x
import sun.x

scala> import jdk.CollectionConverters._
                  ^
       error: object CollectionConverters is not a member of package jdk

Expectation

My expectation was that I had graduated from studying Chapter 2 of the spec.

I needed CollectionConverters for a quickie test and couldn't remember how to spell it.

_root_.jdk should be lowest-priority binding of jdk, below the root context scala that makes scala.jdk available.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions