Skip to content

Commit

Permalink
[guava] fix: resolve implicit conflict for top level collection funne…
Browse files Browse the repository at this point in the history
…ls (#936)

* [guava] fix: resolve implicit conflict for top level collection funnels

* Fix / filter binary issues
  • Loading branch information
RustedBones authored Mar 20, 2024
1 parent 4cb80a0 commit 673351d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ ThisBuild / githubWorkflowAddedJobs ++= Seq(
)

// mima
ThisBuild / mimaBinaryIssueFilters ++= Seq()
ThisBuild / mimaBinaryIssueFilters ++= Seq(
// genFunnelMacro should not be available to users
ProblemFilters.exclude[DirectMissingMethodProblem]("magnolify.guava.auto.package.genFunnelMacro")
)
ThisBuild / tlVersionIntroduced := Map("3" -> "0.8.0")

// protobuf
Expand Down
27 changes: 27 additions & 0 deletions guava/src/main/scala/magnolify/guava/GuavaMacros.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package magnolify.guava

import scala.reflect.macros.whitebox

private object GuavaMacros {
def genFunnelMacro[T: c.WeakTypeTag](c: whitebox.Context): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.guava.semiauto.FunnelDerivation.apply[$wtt]"""
}
}
12 changes: 3 additions & 9 deletions guava/src/main/scala/magnolify/guava/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ package magnolify.guava
import com.google.common.hash.Funnel
import magnolify.guava.semiauto.FunnelImplicits

import scala.reflect.macros._
package object auto extends FunnelImplicits with LowPriorityImplicits

package object auto extends FunnelImplicits {
def genFunnelMacro[T: c.WeakTypeTag](c: whitebox.Context): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.guava.semiauto.FunnelDerivation.apply[$wtt]"""
}

implicit def genFunnel[T]: Funnel[T] = macro genFunnelMacro[T]
trait LowPriorityImplicits {
implicit def genFunnel[T]: Funnel[T] = macro GuavaMacros.genFunnelMacro[T]
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ class FunnelDerivationSuite extends MagnolifySuite {
test[Collections]
test[Custom]

// test unwrapped
test[Int]
test[List[Int]]
test[List[Required]]

test("AnyVal") {
implicit val f: Funnel[HasValueClass] = FunnelDerivation[HasValueClass]
test[HasValueClass]
Expand Down

0 comments on commit 673351d

Please sign in to comment.