From 26dec8fbeb38d6fc9c6fc751f43dea4ddc5458cd Mon Sep 17 00:00:00 2001 From: Nadav Samet Date: Fri, 29 Dec 2023 09:57:32 -0800 Subject: [PATCH] Add full name for Option to resolve name conflicts Fixes #1623 --- .../scalapb/compiler/ParseFromGenerator.scala | 2 +- .../scalapb/compiler/ProtobufGenerator.scala | 2 +- e2e/src/main/protobuf/issue1623.proto | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 e2e/src/main/protobuf/issue1623.proto diff --git a/compiler-plugin/src/main/scala/scalapb/compiler/ParseFromGenerator.scala b/compiler-plugin/src/main/scala/scalapb/compiler/ParseFromGenerator.scala index 45bcfe6af..1ef3923ee 100644 --- a/compiler-plugin/src/main/scala/scalapb/compiler/ParseFromGenerator.scala +++ b/compiler-plugin/src/main/scala/scalapb/compiler/ParseFromGenerator.scala @@ -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" diff --git a/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala b/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala index 7cd809ad2..b3e322ba5 100644 --- a/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala +++ b/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala @@ -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 diff --git a/e2e/src/main/protobuf/issue1623.proto b/e2e/src/main/protobuf/issue1623.proto new file mode 100644 index 000000000..ab05ce193 --- /dev/null +++ b/e2e/src/main/protobuf/issue1623.proto @@ -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; + } +}