Skip to content

Commit 26987f8

Browse files
Merge branch 'master' into fix-oneof-import-conflict-test
2 parents eba99d0 + 07b7799 commit 26987f8

File tree

87 files changed

+1972
-2734
lines changed

Some content is hidden

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

87 files changed

+1972
-2734
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.

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ jobs:
137137

138138
gh_release:
139139
if: startsWith(github.ref, 'refs/tags/v')
140-
runs-on: ubuntu-20.04
140+
runs-on: ubuntu-latest
141141
needs: [native, scalapbc]
142142
steps:
143143
- uses: actions/checkout@v4

.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
@@ -400,7 +400,7 @@ class ProtobufGenerator(
400400
)
401401
if (f.supportsPresence || f.isInOneof)
402402
fp.add(s"case ${f.getNumber} => $e.orNull")
403-
else if (f.isOptional && !f.noBoxRequired) {
403+
else if (f.isSingularOptional && !f.noBoxRequired) {
404404
// In proto3, drop default value
405405
fp.add(s"case ${f.getNumber} => {")
406406
.indent
@@ -554,7 +554,7 @@ class ProtobufGenerator(
554554
| }
555555
|};""".stripMargin
556556
)
557-
} else if (field.isOptional) {
557+
} else if (field.isSingularOptional) {
558558
fp.add(
559559
s"""if ($fieldNameSymbol.isDefined) {
560560
| val __value = ${toBaseType(field)(fieldNameSymbol + ".get")}
@@ -754,7 +754,7 @@ class ProtobufGenerator(
754754
val typeName = field.scalaTypeName
755755
val ctorDefaultValue: Option[String] =
756756
if (field.noDefaultValueInConstructor) None
757-
else if (field.isOptional && field.supportsPresence) Some(C.None)
757+
else if (field.isSingularOptional && field.supportsPresence) Some(C.None)
758758
else if (field.isSingular && !field.isRequired && !field.noBoxRequired)
759759
Some(defaultValueForGet(field).toString)
760760
else if (field.isRepeated && !field.collection.nonEmptyType)

0 commit comments

Comments
 (0)