Skip to content

Commit

Permalink
Add full name for Option to resolve name conflicts
Browse files Browse the repository at this point in the history
Fixes #1623
  • Loading branch information
thesamet committed Dec 29, 2023
1 parent 688ddae commit 26dec8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private[compiler] class ParseFromGenerator(
if (!usesBaseTypeInBuilder(field)) toCustomType(field)(newValBase) else newValBase

val updateOp =
if (field.supportsPresence) s"__${field.scalaName} = Option($newVal)"
if (field.supportsPresence) s"__${field.scalaName} = _root_.scala.Option($newVal)"
else if (field.isInOneof) {
s"__${field.getContainingOneof.scalaName.name} = ${field.oneOfTypeName.fullName}($newVal)"
} else if (field.isRepeated) s"__${field.scalaName} += $newVal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ class ProtobufGenerator(
.add(
s"""def $fieldName: ${lensType(
field.singleScalaTypeName
)} = field(_.${field.getMethod})((c_, f_) => c_.copy($fieldName = Option(f_)))
)} = field(_.${field.getMethod})((c_, f_) => c_.copy($fieldName = _root_.scala.Option(f_)))
|def ${optionLensName}: ${lensType(
field.scalaTypeName
)} = field(_.$fieldName)((c_, f_) => c_.copy($fieldName = f_))""".stripMargin
Expand Down
18 changes: 18 additions & 0 deletions e2e/src/main/protobuf/issue1623.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package com.thesamet.proto.e2e.issue1623;

message CreditCard {};

message PayPal {};

message Money {}

message PaymentMethod {
string id = 1;
Money money = 2;
oneof option {
CreditCard credit_card = 3;
PayPal paypal = 4;
}
}

0 comments on commit 26dec8f

Please sign in to comment.