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

Regression with handling protobuf Empty in 1.7.0 #683

Closed
Krever opened this issue Jan 29, 2025 · 0 comments · Fixed by #684
Closed

Regression with handling protobuf Empty in 1.7.0 #683

Krever opened this issue Jan 29, 2025 · 0 comments · Fixed by #684
Labels
bug Erroneous behavior in existing features

Comments

@Krever
Copy link
Contributor

Krever commented Jan 29, 2025

After upgrading from 1.5.0 to 1.7.0 I noticed that code below doesnt compile anymore (its a minimized version)

syntax = "proto3";

package swissborg.protobuf.ledger.journal;

option java_package = "com.swissborg.protobuf.ledger.journal";

message Foo {
  oneof sealed_value {
    Foo1 foo1 = 1;
  }
}

message Foo1 {}
import com.swissborg.protobuf.ledger.{journal => proto}
import io.scalaland.chimney
import io.scalaland.chimney.protobufs._

sealed trait Foo
object Foo {
  final case class Bar1() extends Foo

  implicit lazy val sagaCodec: chimney.Codec[Foo, proto.Foo] =
    chimney.Codec.define[Foo, proto.Foo]
      .withSealedSubtypeRenamed[Bar1, proto.Foo1]
      .buildCodec

}

It can be further minimized into

    sealed trait Proto extends Product with Serializable
    object Proto {
      case class Foo(a: Int) extends Proto
      case object Empty extends Proto
    }

    sealed trait Domain extends Product with Serializable
    object Domain {
      case class Foo1(a: Int) extends Domain
    }

    implicit def handleEmpty[To]: PartialTransformer[Proto.Empty.type, To] =
      (_: Proto.Empty.type, _: Boolean) => partial.Result.fromEmpty[To]

    (Proto.Foo(10): Proto)
      .intoPartial[Domain]
      .withSealedSubtypeRenamed[Proto.Foo, Domain.Foo1]
      .transform
      .asOption ==> Some(Domain.Foo1(10))
    (Proto.Empty: Proto)
      .intoPartial[Domain]
      .withSealedSubtypeRenamed[Proto.Foo, Domain.Foo1]
      .transform
      .asOption ==> None
@Krever Krever added the bug Erroneous behavior in existing features label Jan 29, 2025
@MateuszKubuszok MateuszKubuszok linked a pull request Jan 29, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Erroneous behavior in existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant