Unable to complile generated code with -language:strictEquality
steinybot opened this issue · 2 comments
steinybot commented
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
Workaround:
given CanEqual[RequestMessage.SealedValue.Empty.type, RequestMessage.SealedValue] = CanEqual.derived
given CanEqual[Request.Empty.type, Request] = CanEqual.derived
thesamet commented
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.