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 in otavia-projects/otavia under -Yexplicit-nulls #19844

Closed
WojciechMazur opened this issue Mar 1, 2024 · 3 comments
Closed

Comments

@WojciechMazur
Copy link
Contributor

Code no longer compiles when -Yexplicit-nulls is used.
Based on Open CB failure of otavia-projects/otavia - build logs

Compiler version

3.4.0

Last good release: 3.3.2-RC1-bin-20230605-348729e-NIGHTLY
First bad release: 3.3.2-RC1-bin-20230606-5d2812a-NIGHTLY
Bisect points to 3e1fbd6

Minimized code

//> using options -Yexplicit-nulls

sealed trait Message extends Serializable
type MessageOf[A <: Actor[?]] <: Call = A match {
    case Actor[m] => m
}

sealed trait Call extends Message
trait Ask[R <: Reply] extends Call

type ReplyOf[A <: Ask[? <: Reply]] <: Reply = A match
    case Ask[r] => r

trait Reply extends Message
sealed trait UnitReply private () extends Reply

trait Future[+V]
sealed trait MessageFuture[+R <: Reply] extends Future[R]

trait Actor[+M <: Call]

trait Address[-M <: Call]: // extends EventableAddress {
  def send[A <: M & Ask[? <: Reply]](send: A): Unit
  def ask[A <: M & Ask[? <: Reply]](ask: A, future: MessageFuture[ReplyOf[A]]): MessageFuture[ReplyOf[A]]

final case class AcceptedChannel() extends Ask[UnitReply]
abstract class AcceptedWorkerActor[M <: Call] extends Actor[M | AcceptedChannel]
abstract class AcceptorActor[W <: AcceptedWorkerActor[? <: Call]]{
    private var workers: Address[MessageOf[W]] = ???

    def future: MessageFuture[UnitReply] = ???
    def case1 = workers.send(AcceptedChannel()) // error
    def case2 = workers.ask(AcceptedChannel(), future) // error
}

Output

Compiling project (Scala 3.4.0, JVM (17))
[error] ./bisect/main.scala:32:30
[error] Found:    AcceptedChannel
[error] Required: MessageOf[W] & Ask[? <: Reply]
[error]     def case1 = workers.send(AcceptedChannel()) // error
[error]                              ^^^^^^^^^^^^^^^^^
[error] ./bisect/main.scala:33:29
[error] Found:    AcceptedChannel
[error] Required: MessageOf[W] & Ask[? <: Reply]
[error]     def case2 = workers.ask(AcceptedChannel(), future) // error
[error]                             ^^^^^^^^^^^^^^^^^
[error] ./bisect/main.scala:33:48
[error] Found:    MessageFuture[UnitReply]
[error] Required: MessageFuture[ReplyOf[A]]
[error] 
[error] where:    A is a type variable with constraint <: MessageOf[W] & Ask[? <: Reply]
[error] 
[error] 
[error] Note: a match type could not be fully reduced:
[error] 
[error]   trying to reduce  ReplyOf[A]
[error]   failed since selector W
[error]   does not uniquely determine parameter m in
[error]     case Actor[m] => m
[error]   The computed bounds for the parameter are:
[error]     m <: Call | AcceptedChannel
[error]     def case2 = workers.ask(AcceptedChannel(), future) // error
[error]                                                ^^^^^^
Error compiling project (Scala 3.4.0, JVM (17))

Expectation

Should probably compile

@WojciechMazur WojciechMazur added itype:bug area:typer regression This worked in a previous version but doesn't anymore labels Mar 1, 2024
@odersky
Copy link
Contributor

odersky commented Mar 1, 2024

-Yexplicit-nulls is unstable, so code might break. @noti0na1 should take a look.

@odersky odersky assigned noti0na1 and unassigned sjrd and odersky Mar 1, 2024
@noti0na1
Copy link
Member

noti0na1 commented Mar 4, 2024

The minimized code produces the same errors with and without explicit nulls, so I don't think it relates to null safety.

After looking at the tests in #17180, I guess the errors are expected?

Could you confirm the expected behaviour? @odersky @sjrd

@bishabosha bishabosha assigned sjrd and unassigned noti0na1 Mar 4, 2024
@sjrd
Copy link
Member

sjrd commented Mar 4, 2024

Oh yes that's expected. In terms of SIP-56 this was made more precise. See occurrences of "concrete type" and in particular the step

If scrutIsWidenedAbstract is true, fail as not specific.

at https://docs.scala-lang.org/sips/match-types-spec.html#matching

@sjrd sjrd closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@sjrd sjrd added itype:invalid and removed regression This worked in a previous version but doesn't anymore labels Mar 4, 2024
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

4 participants