scalapb / ScalaPB

Protocol buffer compiler for Scala.
https://scalapb.github.io/
Apache License 2.0
1.3k stars 280 forks source link

Unable to complile generated code with -language:strictEquality #1705

Closed steinybot closed 3 weeks ago

steinybot commented 3 months ago

test.proto:

syntax = "proto3";

package bugs;

message Request {
    oneof sealed_value {
        Echo echo = 1;
    }
}

message Echo {
    string message = 1;
}

build.sbt:

scalaVersion := "3.4.2"

Compile / PB.targets := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)

libraryDependencies ++= Seq(
  "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion
)

scalacOptions += "-language:strictEquality"

compile fails with:

[error] -- [E172] Type Error: /Users/jason/src/bug-reports/target/scala-3.4.2/src_managed/main/scalapb/kyo/grpc/test/Request.scala:25:11
[error] 25 |      case kyo.grpc.test.RequestMessage.SealedValue.Empty => Empty
[error]    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |Values of types object kyo.grpc.test.RequestMessage.SealedValue.Empty and kyo.grpc.test.RequestMessage.SealedValue cannot be compared with == or !=
[error] -- [E172] Type Error: /Users/jason/src/bug-reports/target/scala-3.4.2/src_managed/main/scalapb/kyo/grpc/test/Request.scala:29:11
[error] 29 |      case Empty => kyo.grpc.test.RequestMessage.SealedValue.Empty
[error]    |           ^^^^^
[error]    |Values of types object kyo.grpc.test.Request.Empty and kyo.grpc.test.Request cannot be compared with == or !=

Reproduction: https://github.com/steinybot/bug-reports/tree/scalapb/strict-equality-oneof

steinybot commented 3 months ago

Workaround:

given CanEqual[RequestMessage.SealedValue.Empty.type, RequestMessage.SealedValue] = CanEqual.derived
given CanEqual[Request.Empty.type, Request] = CanEqual.derived
thesamet commented 3 weeks ago

I've started working on this, and will leave this branch for the time being. It seems like this would create enough deviation between Scala 3 and increased complexity to not be worthwhile including as this will only serve a small subset of users until strictequality hits mainstream. I am happy to reconsider at a future time if this is a popular request.