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

Interacting with Java's PolymorphicSignature seems broken #15550

Closed
oscar-broman opened this issue Jun 29, 2022 · 1 comment
Closed

Interacting with Java's PolymorphicSignature seems broken #15550

oscar-broman opened this issue Jun 29, 2022 · 1 comment

Comments

@oscar-broman
Copy link

oscar-broman commented Jun 29, 2022

Compiler version

Tried 3.1.3 and 3.2.0-RC1

Minimized code

Since this example uses the foreign incubator API, javaOptions and javacOptions must contain --add-modules=jdk.incubator.foreign

object Test {
  def main(args: Array[String]): Unit = {
    import jdk.incubator.foreign.ValueLayout.{JAVA_DOUBLE, JAVA_INT, JAVA_LONG, ADDRESS}
    import jdk.incubator.foreign.{CLinker, ResourceScope, MemorySegment, FunctionDescriptor}

    val linker = CLinker.systemCLinker()
    val strlen = linker.downcallHandle(
      linker.lookup("strlen").get(),
      FunctionDescriptor.of(JAVA_LONG, ADDRESS),
    )

    val scope = ResourceScope.newSharedScope()
    val x = MemorySegment.allocateNative(10, scope)
    x.setUtf8String(0, "Hello")
    val len = strlen.invoke(x.address())
    println(s"len = $len")
  }
}

Output

[info] running (fork) Test
[error] WARNING: Using incubator modules: jdk.incubator.foreign
[error] Exception in thread "main" java.lang.ClassCastException: Cannot cast [Ljava.lang.Object; to jdk.incubator.foreign.Addressable
[error] 	at java.base/java.lang.Class.cast(Class.java:3921)
[error] 	at Test$.main(Test.scala:15)
[error] 	at Test.main(Test.scala)
[error] Nonzero exit code returned from runner: 1
[error] (Compile / run) Nonzero exit code returned from runner: 1

Expectation

The code should run just fine, and print len = 5. It works in Scala 2.

@oscar-broman oscar-broman added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 29, 2022
@smarter
Copy link
Member

smarter commented Jun 29, 2022

Duplicate of #11332

@smarter smarter marked this as a duplicate of #11332 Jun 29, 2022
@smarter smarter closed this as completed Jun 29, 2022
@griggt griggt added stat:duplicate and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants