Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String#codePoints does not compile on scala.js #4925

Open
pontaoski opened this issue Jan 4, 2024 · 6 comments
Open

String#codePoints does not compile on scala.js #4925

pontaoski opened this issue Jan 4, 2024 · 6 comments
Labels
missing javalib Report of something from the JDK that is missing (does not link)

Comments

@pontaoski
Copy link

val codepoints: Array[Int] = "foo".codePoints.toArray
[error] Referring to non-existent method java.util.stream.IntStream.toArray()[int
[error]   dispatched from java.util.stream.IntStream.toArray()[int
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1$$anonfun$1(scala.collection.immutable.Map,scala.Tuple2,scala.Tuple2)boolean
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1(scala.collection.immutable.Map,scala.collection.immutable.SortedMap)scala.collection.immutable.List
[error]   called from Shades.StringStore.idsSortedAccordingTo(scala.collection.immutable.Map)fs2.concurrent.Signal
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2$$anonfun$8(Shades.StringStore,scala.Option)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel,fs2.concurrent.Signal)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3(Shades.StringStore)cats.effect.kernel.Resource
[error]   called from Shades.Main$.render()cats.effect.kernel.Resource
[error]   dispatched from calico.IOWebApp.render()cats.effect.kernel.Resource
[error]   called from private calico.IOWebApp.main$$anonfun$1(org.scalajs.dom.Element)cats.effect.IO
[error]   called from calico.IOWebApp.main([java.lang.String)void
[error]   called from Shades.Main$.main([java.lang.String)void
[error]   called from static Shades.Main.main([java.lang.String)void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   Shades.StringStore
[error]   Shades.Main$
[error] Referring to non-existent class java.util.stream.IntStream
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1$$anonfun$1(scala.collection.immutable.Map,scala.Tuple2,scala.Tuple2)boolean
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1(scala.collection.immutable.Map,scala.collection.immutable.SortedMap)scala.collection.immutable.List
[error]   called from Shades.StringStore.idsSortedAccordingTo(scala.collection.immutable.Map)fs2.concurrent.Signal
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2$$anonfun$8(Shades.StringStore,scala.Option)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel,fs2.concurrent.Signal)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3(Shades.StringStore)cats.effect.kernel.Resource
[error]   called from Shades.Main$.render()cats.effect.kernel.Resource
[error]   dispatched from calico.IOWebApp.render()cats.effect.kernel.Resource
[error]   called from private calico.IOWebApp.main$$anonfun$1(org.scalajs.dom.Element)cats.effect.IO
[error]   called from calico.IOWebApp.main([java.lang.String)void
[error]   called from Shades.Main$.main([java.lang.String)void
[error]   called from static Shades.Main.main([java.lang.String)void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   Shades.StringStore
[error]   Shades.Main$
[error] Referring to non-existent method java.lang.String.codePoints()java.util.stream.IntStream
[error]   dispatched from java.lang.String.codePoints()java.util.stream.IntStream
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1$$anonfun$1(scala.collection.immutable.Map,scala.Tuple2,scala.Tuple2)boolean
[error]   called from private static Shades.StringStore.idsSortedAccordingTo$$anonfun$1(scala.collection.immutable.Map,scala.collection.immutable.SortedMap)scala.collection.immutable.List
[error]   called from Shades.StringStore.idsSortedAccordingTo(scala.collection.immutable.Map)fs2.concurrent.Signal
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2$$anonfun$8(Shades.StringStore,scala.Option)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel,fs2.concurrent.Signal)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3$$anonfun$2(Shades.StringStore,fs2.concurrent.Channel)cats.effect.kernel.Resource
[error]   called from private Shades.Main$.render$$anonfun$3(Shades.StringStore)cats.effect.kernel.Resource
[error]   called from Shades.Main$.render()cats.effect.kernel.Resource
[error]   dispatched from calico.IOWebApp.render()cats.effect.kernel.Resource
[error]   called from private calico.IOWebApp.main$$anonfun$1(org.scalajs.dom.Element)cats.effect.IO
[error]   called from calico.IOWebApp.main([java.lang.String)void
[error]   called from Shades.Main$.main([java.lang.String)void
[error]   called from static Shades.Main.main([java.lang.String)void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   Shades.StringStore
[error]   Shades.Main$
[error] There were linking errors

scala: 3.3.1
scalajs: 1.15.0

@ekrich
Copy link
Contributor

ekrich commented Jan 5, 2024

Is it possible to use a different method to get the codepoints? Maybe something like the following could work?

scala> "A\u00ea\u00f1\u00fcC".map(_.toInt).toArray
res4: Array[Int] = Array(65, 234, 241, 252, 67)

scala> res4.map(_.toChar)
res6: Array[Char] = Array(A, ê, ñ, ü, C)

The method codePoints was added in Java 9 and it requires the java.util.stream API which is a big lift.

@gzm0 gzm0 added the missing javalib Report of something from the JDK that is missing (does not link) label Jan 5, 2024
@gzm0
Copy link
Contributor

gzm0 commented Jan 5, 2024

Heads up: char != code point (look up surrogate pairs for more, sorry for the brief comment, on mobile)

@sjrd
Copy link
Member

sjrd commented Jan 5, 2024

Java Streams are not supported and will most likely never be. They inherently require parallel capabilities. So Stream-related methods like codePoints cannot be supported either.

Use String.codePointAt and Character.charCount to iterate over the code points of a String.

@sjrd sjrd added the wontfix We decided not to fix this issue/not implement that feature request. label Jan 5, 2024
@sjrd sjrd closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@gzm0
Copy link
Contributor

gzm0 commented Jan 5, 2024

Java Streams are not supported and will most likely never be. They inherently require parallel capabilities.

Huh, this is the first time I'm hearing this.

Feels like a pretty severe limitation we should document? (that we cannot support streams. I mean I realize that it for sure is a lot of work).

@sjrd
Copy link
Member

sjrd commented Jan 5, 2024

I don't remember exactly what led me to that conclusion, but I remember I had already looked at it and it seemed unavoidable.

@sjrd
Copy link
Member

sjrd commented Jan 7, 2024

Reopening but depends on #4926.

@sjrd sjrd reopened this Jan 7, 2024
@gzm0 gzm0 removed the wontfix We decided not to fix this issue/not implement that feature request. label Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing javalib Report of something from the JDK that is missing (does not link)
Projects
None yet
Development

No branches or pull requests

4 participants