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

Typer regression introduced in #15746 #15934

Closed
WojciechMazur opened this issue Aug 30, 2022 · 1 comment · Fixed by #15936
Closed

Typer regression introduced in #15746 #15934

WojciechMazur opened this issue Aug 30, 2022 · 1 comment · Fixed by #15936
Labels
itype:bug regression This worked in a previous version but doesn't anymore stat:needs triage Every issue needs to have an "area" and "itype" label
Milestone

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Aug 30, 2022

1st out of 2 regressions found when testing #15746 in Open Community Build.
Regression found in akka/akka sources

Compiler version

3.2.1-nightly

Minimized code

trait ReplicatedData
trait ActorRef[-T] {
  def tell(msg: T): Unit = ???
}

// shared in both domains
abstract class Key[+T <: ReplicatedData]

// domain 1
object dd {
  sealed abstract class GetResponse[A <: ReplicatedData] {
    def key: Key[A]
  }
  case class GetSuccess[A <: ReplicatedData](key: Key[A]) extends GetResponse[A]
  case class GetFailure[A <: ReplicatedData](key: Key[A]) extends GetResponse[A]
}

// domain 2
object JReplicator {
  final case class Get[A <: ReplicatedData](
      key: Key[A],
      replyTo: ActorRef[GetResponse[A]]
  )
  sealed abstract class GetResponse[A <: ReplicatedData] {
    def key: Key[A]
  }
  case class GetSuccess[A <: ReplicatedData](key: Key[A]) extends GetResponse[A]
  case class GetFailure[A <: ReplicatedData](key: Key[A]) extends GetResponse[A]
}

val _ = null.asInstanceOf[Any] match {
  case cmd: JReplicator.Get[d] =>
    val reply =
      util
        .Try[dd.GetResponse[d]](???)
        .map {
          // Needs at least 2 cases to triger failure
          case rsp: dd.GetSuccess[d]  => JReplicator.GetSuccess(rsp.key)
          case rsp: dd.GetResponse[d] => JReplicator.GetFailure(rsp.key)
        }
        // needs recover to trigger failure
        .recover { case _ => new JReplicator.GetFailure(cmd.key) }
    reply.foreach { cmd.replyTo tell _ } // error
}

Output

[error] ./test.scala:44:38: 
[error] Found:    JReplicator.GetResponse[?1.CAP]
[error] Required: JReplicator.GetResponse[d]
[error] 
[error] where:    ?1 is an unknown value of type scala.runtime.TypeBox[d, ReplicatedData]
[error]           d  is a type locally defined in package object test$package with bounds <: ReplicatedData
[error]     reply.foreach { cmd.replyTo tell _ }
[error]     

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug regression This worked in a previous version but doesn't anymore stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 30, 2022
@odersky
Copy link
Contributor

odersky commented Aug 30, 2022

workaround:

   .map[JReplicator.GetResponse[d]] { ...

odersky added a commit to dotty-staging/dotty that referenced this issue Aug 30, 2022
Don't instantiate co- and contravariant inner type variables eagerly.
Lift them instead to the reference level, same as for invariant type variables.

Fixes scala#15934
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug regression This worked in a previous version but doesn't anymore stat:needs triage Every issue needs to have an "area" and "itype" label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants