Skip to content

Commit d155813

Browse files
committed
Generate oneofs as sealed abstract class
Fixes #1694
1 parent a1dd2d6 commit d155813

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Bump protobuf and protoc to 4.26.0. Currently files must specify proto2 and
44
proto3 syntax. Editions are not supported yet.
55
- References to descriptors are fully qualified (#1724)
6+
- Oneofs are now generated as sealed abstract class instead of sealed traits (#1694)
67

78
## [0.11.18] (Unreleased)
89
- References to descriptors are fully qualified (#1724)

compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ class ProtobufGenerator(
115115

116116
def printOneof(printer: FunctionalPrinter, e: OneofDescriptor): FunctionalPrinter = {
117117
printer
118-
.add(s"sealed trait ${e.scalaType.nameSymbol} extends ${e.baseClasses.mkString(" with ")} {")
118+
.add(
119+
s"sealed abstract class ${e.scalaType.nameSymbol} extends ${e.baseClasses.mkString(" with ")} {"
120+
)
119121
.indent
120122
.add(s"def isEmpty: _root_.scala.Boolean = false")
121123
.add(s"def isDefined: _root_.scala.Boolean = true")

scalapb-runtime/src/main/js-native/com/google/protobuf/struct/Value.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ object Value extends scalapb.GeneratedMessageCompanion[com.google.protobuf.struc
195195
lazy val defaultInstance = com.google.protobuf.struct.Value(
196196
kind = com.google.protobuf.struct.Value.Kind.Empty
197197
)
198-
sealed trait Kind extends _root_.scalapb.GeneratedOneof {
198+
sealed abstract class Kind extends _root_.scalapb.GeneratedOneof {
199199
def isEmpty: _root_.scala.Boolean = false
200200
def isDefined: _root_.scala.Boolean = true
201201
def isNullValue: _root_.scala.Boolean = false

scalapb-runtime/src/main/scalajvm/com/google/protobuf/struct/Value.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object Value extends scalapb.GeneratedMessageCompanion[com.google.protobuf.struc
216216
lazy val defaultInstance = com.google.protobuf.struct.Value(
217217
kind = com.google.protobuf.struct.Value.Kind.Empty
218218
)
219-
sealed trait Kind extends _root_.scalapb.GeneratedOneof {
219+
sealed abstract class Kind extends _root_.scalapb.GeneratedOneof {
220220
def isEmpty: _root_.scala.Boolean = false
221221
def isDefined: _root_.scala.Boolean = true
222222
def isNullValue: _root_.scala.Boolean = false

0 commit comments

Comments
 (0)