Skip to content

Regression in apache/incubator-pekko - invalid type inference #19001

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
WojciechMazur opened this issue Nov 20, 2023 · 2 comments · Fixed by #19189
Closed

Regression in apache/incubator-pekko - invalid type inference #19001

WojciechMazur opened this issue Nov 20, 2023 · 2 comments · Fixed by #19189
Assignees
Labels
area:infer area:typer itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Based on Open CB failure for apache/incubator-pekko - build logs

Compiler version

Since 3.4.0-RC1-bin-20231113-0dfe593-NIGHTLY

Bisect points to a196167

Minimized code

import java.util.concurrent.CompletionStage
import scala.concurrent.Future


trait ActorRef[-T]{
   def ask[Res](replyTo: ActorRef[Res] => T): Future[Res] = ???
}


implicit final class FutureOps[T](private val f: Future[T]) extends AnyVal {
  def asJava: CompletionStage[T] = ???
}

class AskPattern[Req, Res] {
  val actor: ActorRef[Req] = ???
  val messageFactory: ActorRef[Res] => Req = ???

  def failing(): CompletionStage[Res] = actor.ask(messageFactory.apply).asJava
  def workaround1(): CompletionStage[Res] = actor.ask[Res](messageFactory.apply).asJava
  def workaround2(): CompletionStage[Res] = actor.ask(messageFactory).asJava

  val jMessageFactory: java.util.function.Function[ActorRef[Res], Req] = ???
  def originalFailingCase(): CompletionStage[Res] = actor.ask(jMessageFactory.apply).asJava
}

Output

-- [E007] Type Mismatch Error: /Users/wmazur/projects/dotty/bisect/main.scala:18:72 
18 |  def failing(): CompletionStage[Res] = actor.ask(messageFactory.apply).asJava
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                     Found:    java.util.concurrent.CompletionStage[Any]
   |                     Required: java.util.concurrent.CompletionStage[Res]
   |
   | longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: /Users/wmazur/projects/dotty/bisect/main.scala:23:84 
23 |  def originalFailingCase(): CompletionStage[Res] = actor.ask(messageFactory.apply).asJava
   |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                     Found:    java.util.concurrent.CompletionStage[Any]
   |                     Required: java.util.concurrent.CompletionStage[Res]
   |

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore area: type inference labels Nov 20, 2023
@WojciechMazur
Copy link
Contributor Author

Another reproduction of code that started to fail since the same commit

import scala.util.{Try, Success, Failure}

trait ActorRef[-T]
trait ActorContext[T] {
  def ask[Req, Res](target: ActorRef[Req], createRequest: ActorRef[Res] => Req)(
      mapResponse: Try[Res] => T
  ): Unit
}

@main def Test =
  val context: ActorContext[Int] = ???
  val askMeRef: ActorRef[Request] = ???

  case class Request(replyTo: ActorRef[Int])

  context.ask(askMeRef, Request.apply) {
    case Success(res) => res // error: expected Int, got Any
    case Failure(ex)  => throw ex
  }

@WojciechMazur
Copy link
Contributor Author

Yet another minimisation based on creativescala/doodle Open CB logs

trait IO[A]:
  def map[B](f: A => B): IO[B] = ???

trait RenderResult[T]:
  def value: T

def IOasync[T](f: (Either[Throwable, T] => Unit) => Unit): IO[T] = ???

def render[T]: IO[T] = {
  def register(cb: Either[Throwable, RenderResult[T]] => Unit): Unit = ???
  IOasync(register).map(_.value) // map should take RenderResult[T], but uses Any
}

yields:

[error] ./main.scala:11:25
[error] value value is not a member of Any
[error]   IOasync(register).map(_.value)
[error]        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:infer area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants