Skip to content

Unexpected Error when resolving the right overloaded method #23799

@He-Pin

Description

@He-Pin

Compiler version

3.3.6

Minimized code

https://github.com/apache/pekko/blob/main/actor/src/main/scala/org/apache/pekko/pattern/FutureTimeoutSupport.scala#L145

If I remove the (), it then compiles error.

//> using scala "3.3.6"

import java.util.concurrent.{ CompletionStage, TimeoutException }
import scala.concurrent.duration.FiniteDuration

def scheduleOnce(delay: java.time.Duration, runnable: Runnable): Unit = ???
def scheduleOnce(delay: FiniteDuration, runnable: Runnable): Unit = ???
def scheduleOnce(delay: FiniteDuration)(f: => Unit): Unit = ???

def timeoutCompletionStage[T](duration: java.time.Duration)(value: => CompletionStage[T]): Unit = {
  val stage = value
  val p = new java.util.concurrent.CompletableFuture[T]
  scheduleOnce(
    duration,
    () => {
      p.completeExceptionally(new TimeoutException(s"Timeout of $duration expired"))
      stage.toCompletableFuture.cancel(true)
    }
  )
}

Output

[error] -- [E134] Type Error: /Users/hepin/IdeaProjects/pekko/actor/src/main/scala/org/apache/pekko/pattern/FutureTimeoutSupport.scala:141:26 
[error] 141 |      val timeout = using.scheduleOnce(duration,
[error]     |                    ^^^^^^^^^^^^^^^^^^
[error]     |None of the overloaded alternatives of method scheduleOnce in trait Scheduler with types
[error]     | (delay: java.time.Duration, runnable: Runnable)
[error]     |  (implicit executor: scala.concurrent.ExecutionContext):
[error]     |    org.apache.pekko.actor.Cancellable
[error]     | (delay: scala.concurrent.duration.FiniteDuration, runnable: Runnable)
[error]     |  (implicit executor: scala.concurrent.ExecutionContext):
[error]     |    org.apache.pekko.actor.Cancellable
[error]     | (delay: scala.concurrent.duration.FiniteDuration)
[error]     |  (f: => Unit)
[error]     |    (implicit executor: scala.concurrent.ExecutionContext):
[error]     |      org.apache.pekko.actor.Cancellable
[error]     | (delay: java.time.Duration, receiver: org.apache.pekko.actor.ActorRef,
[error]     |  message: Any, executor: scala.concurrent.ExecutionContext, sender:
[error]     |  org.apache.pekko.actor.ActorRef): org.apache.pekko.actor.Cancellable
[error]     | (delay: scala.concurrent.duration.FiniteDuration,
[error]     |  receiver: org.apache.pekko.actor.ActorRef, message: Any)
[error]     |  (implicit executor: scala.concurrent.ExecutionContext, sender:
[error]     |    org.apache.pekko.actor.ActorRef): org.apache.pekko.actor.Cancellable
[error]     |match arguments ((duration² : java.time.Duration), () => Boolean)
[error]     |
[error]     |where:    duration  is a package in package scala.concurrent
[error]     |          duration² is a parameter in method timeoutCompletionStage
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

It should compile, or just gives expect () => Unit of runnable ,but got () => Boolean,

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