Skip to content

Commit 725eddd

Browse files
committed
Upgrade to protobuf 4.32
1 parent fed8ef6 commit 725eddd

File tree

86 files changed

+1971
-2733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1971
-2733
lines changed

.direnv/bin/nix-direnv-reload

Lines changed: 0 additions & 19 deletions
This file was deleted.

.direnv/nix-profile-25.05-vj980b72z6zb0yg6

Lines changed: 0 additions & 1 deletion
This file was deleted.

.direnv/nix-profile-25.05-vj980b72z6zb0yg6.rc

Lines changed: 0 additions & 2147 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.vscode/
22
.bloop/
33
.metals/
4+
.direnv
45
project/.bloop/
56
metals.sbt
67

build.sbt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BuildHelper._
33
import Dependencies._
44
import sbtassembly.AssemblyPlugin.defaultUniversalScript
55

6-
val protobufCompilerVersion = "4.28.3"
6+
val protobufCompilerVersion = "4.32.0"
77

88
val MimaPreviousVersion = "0.11.0"
99

@@ -71,7 +71,10 @@ lazy val runtime = (projectMatrix in file("scalapb-runtime"))
7171
Seq(
7272
"-Wconf:msg=[Uu]nused&origin=scala[.]collection[.]compat._:s",
7373
"-Wconf:cat=deprecation&msg=.*[Jj]avaGenerateEqualsAndHash.*deprecated.*:s",
74-
"-Wconf:cat=deprecation&msg=.*[dD]eprecatedLegacyJsonFieldConflicts:s"
74+
"-Wconf:cat=deprecation&msg=.*[dD]eprecatedLegacyJsonFieldConflicts:s",
75+
"-Wconf:cat=deprecation&msg=.*[eE]dition.*deprecated.*:s",
76+
"-Wconf:cat=deprecation&msg=.*[wW]eak.*:s",
77+
"-Wconf:cat=deprecation&msg=.*[sS]yntax.*:s"
7578
)
7679
case _ => Seq.empty // Scala 2.12 or other (e.g. pre-2.13)
7780
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ class DescriptorImplicits private[compiler] (
203203

204204
def isSealedOneofType: Boolean = fd.isMessage && fd.getMessageType.isSealedOneofType
205205

206+
// isOptional is deprecated in protobuf-java.
207+
def isSingularOptional: Boolean = !fd.isRequired() && !fd.isRepeated()
208+
206209
def scalaName: String =
207210
if (fieldOptions.getScalaName.nonEmpty) fieldOptions.getScalaName
208211
else
@@ -261,7 +264,7 @@ class DescriptorImplicits private[compiler] (
261264
// Is this field boxed inside an Option in Scala. Equivalent, does the Java API
262265
// support hasX methods for this field.
263266
def supportsPresence: Boolean =
264-
fd.hasPresence() && fd.isOptional() && !fd.isInOneof && !noBox && !fd.isSealedOneofType
267+
fd.hasPresence() && fd.isSingularOptional && !fd.isInOneof && !noBox && !fd.isSealedOneofType
265268

266269
// Is the Scala representation of this field a singular type.
267270
def isSingular =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private[compiler] object FieldTransformations {
213213
}
214214

215215
val knownFields = m.getAllFields().asScala.map { case (field, value) =>
216-
if (field.getType() == Type.MESSAGE && !field.isOptional()) {
216+
if (field.getType() == Type.MESSAGE && (field.isRepeated() || field.isRequired())) {
217217
throw new GeneratorException(
218218
s"${context.currentFile}: matching is supported only for scalar types and optional message fields."
219219
)
@@ -230,7 +230,7 @@ private[compiler] object FieldTransformations {
230230
m: Message,
231231
ext: FieldDescriptor
232232
): Message = {
233-
if (ext.getType != Type.MESSAGE || !ext.isOptional) {
233+
if (ext.getType != Type.MESSAGE || ext.isRepeated() || ext.isRequired()) {
234234
throw new GeneratorException(
235235
s"Unknown extension fields must be optional message types: ${ext}"
236236
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ProtoValidation(implicits: DescriptorImplicits) {
145145
throw new GeneratorException(
146146
s"${fd.getFullName}: Field ${fd.getName} is a map and has type specified. Use key_type or value_type instead."
147147
)
148-
if (!fd.isOptional && fd.fieldOptions.hasNoBox)
148+
if (!fd.isSingularOptional && fd.fieldOptions.hasNoBox)
149149
throw new GeneratorException(
150150
s"${fd.getFullName}: Field ${fd.getName} has no_box set but is not an optional field."
151151
)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ class ProtobufGenerator(
379379
)
380380
if (f.supportsPresence || f.isInOneof)
381381
fp.add(s"case ${f.getNumber} => $e.orNull")
382-
else if (f.isOptional && !f.noBoxRequired) {
382+
else if (f.isSingularOptional && !f.noBoxRequired) {
383383
// In proto3, drop default value
384384
fp.add(s"case ${f.getNumber} => {")
385385
.indent
@@ -533,7 +533,7 @@ class ProtobufGenerator(
533533
| }
534534
|};""".stripMargin
535535
)
536-
} else if (field.isOptional) {
536+
} else if (field.isSingularOptional) {
537537
fp.add(
538538
s"""if ($fieldNameSymbol.isDefined) {
539539
| val __value = ${toBaseType(field)(fieldNameSymbol + ".get")}
@@ -733,7 +733,7 @@ class ProtobufGenerator(
733733
val typeName = field.scalaTypeName
734734
val ctorDefaultValue: Option[String] =
735735
if (field.noDefaultValueInConstructor) None
736-
else if (field.isOptional && field.supportsPresence) Some(C.None)
736+
else if (field.isSingularOptional && field.supportsPresence) Some(C.None)
737737
else if (field.isSingular && !field.isRequired && !field.noBoxRequired)
738738
Some(defaultValueForGet(field).toString)
739739
else if (field.isRepeated && !field.collection.nonEmptyType)

project/Dependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Keys._
55
object Dependencies {
66
object versions {
77
val grpc = "1.74.0"
8-
val protobuf = "4.28.3"
8+
val protobuf = "4.32.0"
99
val collectionCompat = "2.13.0"
1010
val coursier = "2.1.24"
1111
val protocGen = "0.9.9"

0 commit comments

Comments
 (0)