transform fails using oneof sealed_value
with empty case
#688
-
I was trying to follow the docs here, but I'm either doing something terrible wrong, or.... The model looks like this. syntax = "proto3";
import "scalapb/scalapb.proto";
package staging.model;
option (scalapb.options) = {
scope: PACKAGE
flat_package: true
package_name: "staging.model.grpcgen"
preserve_unknown_fields: false
};
message Measure {
double value = 1;
optional string units = 2;
}
message Label {
string value = 1;
}
message PropertyValue {
oneof sealed_value {
Measure measure = 1;
Label label = 2;
}
}
message Property {
string name = 1;
PropertyValue value = 2;
optional string description = 3;
} And the domain model I'd like to map it to is: sealed trait PropertyValue
object PropertyValue {
case class Measure(value: Double, units: Option[String] = None) extends PropertyValue
case class Label(value: String) extends PropertyValue
}
case class Property(name: String, value: PropertyValue, description: Option[String] = None) Given ⬆️ , the client code should look like: import staging.model.grpcgen as pb
import io.scalaland.chimney.dsl.*
import io.scalaland.chimney.protobufs.* // includes support for empty scalapb.GeneratedSealedOneof
val domainPropertyValue: PropertyValue = PropertyValue.Label("wombat")
val pbPropertyValue: pb.PropertyValue = pb.Label("wombat")
pbPropertyValue.transformIntoPartial[PropertyValue].asOption == Some(domainPropertyValue) This is failing to compile.
Am I doing something wrong here or do the docs need to be updated? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If I follow the docs and use |
Beta Was this translation helpful? Give feedback.
-
If it's Scala 3, then the issue is probably related to this test, and a reason it's manually edited. This code: // among subtypes of GeneratedSealedOneof only Empty <:< Singleton (case object),
// it allows us to precisely that value and no other
implicit def partialTransformerFromEmptySealedOneOfInstance[From <: scalapb.GeneratedSealedOneof with Singleton, To]
: PartialTransformer[From, To] =
PartialTransformer(_ => partial.Result.fromEmpty) Scala 2 can resolve this implicit inside a macro, while Scala 3 doesn't. Scala 3 CAN resolve it outside a macro. I suspect the issue is that outside a macro it can perform check that |
Beta Was this translation helpful? Give feedback.
If it's Scala 3, then the issue is probably related to this test, and a reason it's manually edited. This code:
Scala 2 can resolve this implicit inside a macro, while Scala 3 doesn't. Scala 3 CAN resolve it outside a macro. I suspect the issue is that outside a macro it can perform check that
Empty.type <:< Singleton
while inside a macro it do…