diff --git a/build.sbt b/build.sbt index c87a568f3..60a316c82 100644 --- a/build.sbt +++ b/build.sbt @@ -152,7 +152,7 @@ lazy val compilerPlugin = (projectMatrix in file("compiler-plugin")) mimaBinaryIssueFilters := Seq( ProblemFilters.exclude[ReversedMissingMethodProblem]("scalapb.options.*"), ProblemFilters.exclude[DirectMissingMethodProblem]("scalapb.compiler.GeneratorParams.*"), - ProblemFilters.exclude[DirectMissingMethodProblem]("scalapb.gen.*"), + ProblemFilters.exclude[DirectMissingMethodProblem]("scalapb.gen.*") ), PB.protocVersion := protobufCompilerVersion, Compile / PB.targets := Seq( diff --git a/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala b/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala index c765d095f..dcb5ee326 100644 --- a/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala +++ b/compiler-plugin/src/main/scala/scalapb/compiler/ProtobufGenerator.scala @@ -944,7 +944,7 @@ class ProtobufGenerator( printer .add( - s"implicit class ${className}Lens[UpperPB](_l: _root_.scalapb.lenses.Lens[UpperPB, ${message.scalaType.fullName}]) extends _root_.scalapb.lenses.ObjectLens[UpperPB, ${message.scalaType.fullName}](_l) {" + s"implicit class ${className}Lens[UpperPB](_l: _root_.scalapb.lenses.Lens[UpperPB, ${message.scalaType.fullName}]) extends ${C.MessageLens}[UpperPB, ${message.scalaType.fullName}](_l) {" ) .indent .print(message.fields) { case (printer, field) => @@ -1470,9 +1470,6 @@ class ProtobufGenerator( .when(javaConverterImport)( _.add(s"import _root_.scalapb.internal.compat.JavaConverters.${C.WildCardImport}").add() ) - .when(params.lenses && params.scala3Sources)( - _.add("import scala.language.adhocExtensions").add() - ) .print(file.scalaOptions.getImportList.asScala) { case (printer, i) => printer.add(s"import $i") } @@ -1730,6 +1727,10 @@ private class Constants(params: GeneratorParams) extends ConstantsBase { if (params.scala3Sources) "private" else "private[this]" val WithOperator: String = if (params.scala3Sources) " & " else " with " + + val MessageLens = + if (params.scala3Sources) "_root_.scalapb.lenses.MessageLens" + else "_root_.scalapb.lenses.ObjectLens" } object ProtobufGenerator { diff --git a/lenses/src/main/scala/scalapb/lenses/Lenses.scala b/lenses/src/main/scala/scalapb/lenses/Lenses.scala index f042b7cdc..c44c6e409 100644 --- a/lenses/src/main/scala/scalapb/lenses/Lenses.scala +++ b/lenses/src/main/scala/scalapb/lenses/Lenses.scala @@ -111,7 +111,6 @@ object Lens extends CompatLensImplicits { } } -/** Represents a lens that has sub-lenses. */ class ObjectLens[U, Container](self: Lens[U, Container]) extends Lens[U, Container] { /** Creates a sub-lens */ @@ -129,6 +128,11 @@ class ObjectLens[U, Container](self: Lens[U, Container]) extends Lens[U, Contain u => set(ms.foldLeft[Container](get(u))((p, m) => m(Lens.unit[Container])(p)))(u) } +// In Scala 3 source mode, message lenses extend this class to avoid an error of extending +// non-open class. +// TODO(thesamet): unify ObjectLens and MessageLens in next major release (#1581) +abstract class MessageLens[U, Container](self: Lens[U, Container]) extends ObjectLens(self) + trait Updatable[A] extends Any { self: A => def update(ms: (Lens[A, A] => Mutation[A])*): A =