Skip to content

no type parameters for method handle: (x$1: java.util.function.BiFunction[_ >: T, Throwable, _ <: U]) #12776

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

Closed
He-Pin opened this issue Apr 20, 2023 · 6 comments

Comments

@He-Pin
Copy link
Contributor

He-Pin commented Apr 20, 2023

Reproduction steps

Scala version: 2.12.17

Works in 2.13

https://github.com/akka/akka/pull/31918/files#diff-f9740bf92e4d83e90e297bde9ecbbb5a624b269455cc21a0c805fd7a0458785cR71-R72

  def afterCompletionStage[T](duration: FiniteDuration, using: Scheduler)(value: => CompletionStage[T])(
      implicit ec: ExecutionContext): CompletionStage[T] =
    if (duration.isFinite && duration.length < 1) {
      try value
      catch { case NonFatal(t) => Futures.failedCompletionStage(t) }
    } else {
      val p = new CompletableFuture[T]
      using.scheduleOnce(duration) {
        try {
          val future = value
          future.handle(new BiFunction[T, Throwable, Unit] {
            override def apply(t: T, ex: Throwable): Unit = {
              if (t != null) p.complete(t)
              if (ex != null) p.completeExceptionally(ex)
            }
          })
        } catch {
          case NonFatal(ex) => p.completeExceptionally(ex)
        }
      }
      p
    }

Problem

[error] C:\Users\hepin\IdeaProjects\akka\akka-actor\src\main\scala\akka\pattern\FutureTimeoutSupport.scala:71:18: no type parameters for method handle: (x$1: java.util.function.BiFunction[_ >: T, Throwable, _ <: U])java.util.concurrent.CompletionStage[U] exist so that it can be applied to arguments (java.util.function.BiFunction[T,Throwable,Unit])
[error]  --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error]  found   : java.util.function.BiFunction[T,Throwable,Unit]
[error]  required: java.util.function.BiFunction[_ >: T, Throwable, _ <: ?U]
[error] Note: T <: Any, but Java-defined trait BiFunction is invariant in type T.
[error] You may wish to investigate a wildcard type such as `_ <: Any`. (SLS 3.2.10)
[error]           future.handle(new BiFunction[T, Throwable, Unit] {
[error]                  ^
[error] C:\Users\hepin\IdeaProjects\akka\akka-actor\src\main\scala\akka\pattern\FutureTimeoutSupport.scala:71:25: type mismatch;
[error]  found   : java.util.function.BiFunction[T,Throwable,Unit]
[error]  required: java.util.function.BiFunction[_ >: T, Throwable, _ <: U]
[error]           future.handle(new BiFunction[T, Throwable, Unit] {
[error]                         ^
[error] two errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 16 s, completed 2023-4-20 23:43:53
[IJ]
@SethTisue
Copy link
Member

We don't keep a ticket open if the bug doesn't exist in 2.13, but the ticket can have value regardless as a place to share workarounds.

Whether a 2.12 backport of the fix would be possible, I don't know — someone would need to do a bisect to figure out what PR fixed this.

@SethTisue
Copy link
Member

SethTisue commented Apr 20, 2023

Note that I'm unable to easily try this code myself since it's missing a lot of needed imports.

@som-snytt
Copy link

Interestingly, 2.13.0 still says

[error]  found   : (String, Throwable) => Unit
[error]  required: java.util.function.BiFunction[_ >: String, Throwable, _]
[error]     val h = g.handle((s, t) => println(s"Unit handling $s on error $t"))
[error]                             ^
[error] one error found

but compiles in 2.13.1.

Minimize is trivialize:

new CompletableFuture[String].handle((s, t) => println(s"Unit handling $s on error $t"))

@He-Pin
Copy link
Contributor Author

He-Pin commented Apr 20, 2023

Hope this get back ported to 2.12.x,with the SAM lamda support too.

@He-Pin
Copy link
Contributor Author

He-Pin commented Apr 20, 2023

We don't keep a ticket open if the bug doesn't exist in 2.13, but the ticket can have value regardless as a place to share workarounds.

Whether a 2.12 backport of the fix would be possible, I don't know — someone would need to do a bisect to figure out what PR fixed this.

The problem is when handling the java Interface with use side varient, and another issue is lack of sam lamda in 2.12.x.

@som-snytt and interesting is the whenComplete compiles

@SethTisue sorry not minimize it as I was want to show which have a real usage

@som-snytt
Copy link

I'm looking at #11558 for a discrete backport. It is not obviously untenable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants