scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Java collection conversions #21297

Open DavidPerezIngeniero opened 3 months ago

DavidPerezIngeniero commented 3 months ago

Compiler version

3.3.3 and 3.4.2

Minimized code

scala-cli -j system -S 2.13.14 --dep org.python:jython-standalone:2.7.1b3

scala> val x = new org.python.core.PyList
val x: org.python.core.PyList = []

scala> import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters._

scala> x.asScala
val res0: scala.collection.mutable.Buffer[_] = Buffer()
Welcome to Scala 3.3.3 (21.0.3, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> val x = new org.python.core.PyList
val x: org.python.core.PyList = []

scala> import scala.jdk.CollectionConverters.*

scala> x.asScala
-- [E008] Not Found Error: -----------------------------------------------------
1 |x.asScala
  |^^^^^^^^^
  |value asScala is not a member of org.python.core.PyList
1 error found

Scala 3.4.2 behaves like 3.3.3

Output

Scala 3 doesn't compile, Scala 2 does.

Expectation

Scala 2 and 3 behave the same

Notes

Take into account that PyList is just a wrapper around java.util.List:

public class PyList extends PySequenceList implements List {
  ....
}

https://stackoverflow.com/questions/78811147/scala-3-bug-in-collection-conversions

Gedochao commented 3 months ago
//> using dep org.python:jython-standalone:2.7.3
//> using scala 3

@main def main = {
  val x = new org.python.core.PyList
  import scala.jdk.CollectionConverters._
  println(x.asScala)
}

Might be helpful to minimize to a Java snippet, rather than using org.python:jython-standalone:2.7.3