Skip to content

Commit

Permalink
Generate oneofs as sealed abstract class
Browse files Browse the repository at this point in the history
Fixes #1694
  • Loading branch information
thesamet committed Sep 22, 2024
1 parent a1dd2d6 commit d155813
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Bump protobuf and protoc to 4.26.0. Currently files must specify proto2 and
proto3 syntax. Editions are not supported yet.
- References to descriptors are fully qualified (#1724)
- Oneofs are now generated as sealed abstract class instead of sealed traits (#1694)

## [0.11.18] (Unreleased)
- References to descriptors are fully qualified (#1724)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ class ProtobufGenerator(

def printOneof(printer: FunctionalPrinter, e: OneofDescriptor): FunctionalPrinter = {
printer
.add(s"sealed trait ${e.scalaType.nameSymbol} extends ${e.baseClasses.mkString(" with ")} {")
.add(
s"sealed abstract class ${e.scalaType.nameSymbol} extends ${e.baseClasses.mkString(" with ")} {"
)
.indent
.add(s"def isEmpty: _root_.scala.Boolean = false")
.add(s"def isDefined: _root_.scala.Boolean = true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ object Value extends scalapb.GeneratedMessageCompanion[com.google.protobuf.struc
lazy val defaultInstance = com.google.protobuf.struct.Value(
kind = com.google.protobuf.struct.Value.Kind.Empty
)
sealed trait Kind extends _root_.scalapb.GeneratedOneof {
sealed abstract class Kind extends _root_.scalapb.GeneratedOneof {
def isEmpty: _root_.scala.Boolean = false
def isDefined: _root_.scala.Boolean = true
def isNullValue: _root_.scala.Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ object Value extends scalapb.GeneratedMessageCompanion[com.google.protobuf.struc
lazy val defaultInstance = com.google.protobuf.struct.Value(
kind = com.google.protobuf.struct.Value.Kind.Empty
)
sealed trait Kind extends _root_.scalapb.GeneratedOneof {
sealed abstract class Kind extends _root_.scalapb.GeneratedOneof {
def isEmpty: _root_.scala.Boolean = false
def isDefined: _root_.scala.Boolean = true
def isNullValue: _root_.scala.Boolean = false
Expand Down

0 comments on commit d155813

Please sign in to comment.