Skip to content

Commit

Permalink
Avoid implicit name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones committed May 27, 2024
1 parent 1d959f1 commit cf5c497
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 179 deletions.
61 changes: 0 additions & 61 deletions cats/src/main/scala-2/magnolify/cats/CatsImplicits.scala

This file was deleted.

90 changes: 50 additions & 40 deletions cats/src/main/scala-2/magnolify/cats/CatsMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,71 +24,77 @@ import scala.reflect.macros.*

private object CatsMacros {

@nowarn("msg=parameter lp in method genShowMacro is never used")
def genShowMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationShow is never used")
def autoDerivationShow[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.ShowDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genEqMacro is never used")
def genEqMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationEq is never used")
def autoDerivationEq[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.EqDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genHashMacro is never used")
def genHashMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationHash is never used")
def autoDerivationHash[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.HashDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genSemigroupMacro is never used")
def genSemigroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationSemigroup is never used")
def autoDerivationSemigroup[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.SemigroupDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genMonoidMacro is never used")
def genMonoidMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationMonoid is never used")
def autoDerivationMonoid[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.MonoidDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genCommutativeSemigroupMacro is never used")
def genCommutativeSemigroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationCommutativeSemigroup is never used")
def autoDerivationCommutativeSemigroup[T: c.WeakTypeTag](
c: whitebox.Context
)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.CommutativeSemigroupDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genCommutativeMonoidMacro is never used")
def genCommutativeMonoidMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationCommutativeMonoid is never used")
def autoDerivationCommutativeMonoid[T: c.WeakTypeTag](
c: whitebox.Context
)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.CommutativeMonoidDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genGroupMacro is never used")
def genGroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationGroup is never used")
def autoDerivationGroup[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.GroupDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genCommutativeGroupMacro is never used")
def genCommutativeGroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationCommutativeGroup is never used")
def autoDerivationCommutativeGroup[T: c.WeakTypeTag](
c: whitebox.Context
)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.CommutativeGroupDerivation.gen[$wtt]"""
}

@nowarn("msg=parameter lp in method genBandMacro is never used")
def genBandMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
@nowarn("msg=parameter lp in method autoDerivationBand is never used")
def autoDerivationBand[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe.*
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.BandDerivation.gen[$wtt]"""
Expand All @@ -103,48 +109,52 @@ private object CatsMacros {
trait AutoDerivation extends LowPriority0Implicits

trait LowPriority0Implicits extends LowPriority1Implicits {
implicit def genShow[T](implicit lp: shapeless.LowPriority): Show[T] =
macro CatsMacros.genShowMacro[T]
implicit def autoDerivationShow[T](implicit lp: shapeless.LowPriority): Show[T] =
macro CatsMacros.autoDerivationShow[T]
// CommutativeGroup <: Group | CommutativeMonoid
implicit def genCommutativeGroup[T](implicit lp: shapeless.LowPriority): CommutativeGroup[T] =
macro CatsMacros.genCommutativeGroupMacro[T]
implicit def autoDerivationCommutativeGroup[T](implicit
lp: shapeless.LowPriority
): CommutativeGroup[T] =
macro CatsMacros.autoDerivationCommutativeGroup[T]
// Hash <: Eq
implicit def genHash[T](implicit lp: shapeless.LowPriority): Hash[T] =
macro CatsMacros.genHashMacro[T]
implicit def autoDerivationHash[T](implicit lp: shapeless.LowPriority): Hash[T] =
macro CatsMacros.autoDerivationHash[T]
}

trait LowPriority1Implicits extends LowPriority2Implicits {
implicit def genEq[T](implicit lp: shapeless.LowPriority): Eq[T] =
macro CatsMacros.genEqMacro[T]
implicit def autoDerivationEq[T](implicit lp: shapeless.LowPriority): Eq[T] =
macro CatsMacros.autoDerivationEq[T]
// Group <: Monoid
implicit def genGroup[T](implicit lp: shapeless.LowPriority): Group[T] =
macro CatsMacros.genGroupMacro[T]
implicit def autoDerivationGroup[T](implicit lp: shapeless.LowPriority): Group[T] =
macro CatsMacros.autoDerivationGroup[T]
}

trait LowPriority2Implicits extends LowPriority3Implicits {
// CommutativeMonoid <: Monoid | CommutativeSemigroup
implicit def genCommutativeMonoid[T](implicit lp: shapeless.LowPriority): CommutativeMonoid[T] =
macro CatsMacros.genCommutativeMonoidMacro[T]
implicit def autoDerivationCommutativeMonoid[T](implicit
lp: shapeless.LowPriority
): CommutativeMonoid[T] =
macro CatsMacros.autoDerivationCommutativeMonoid[T]
}

trait LowPriority3Implicits extends LowPriority4Implicits {
// CommutativeSemigroup <: Semigroup
implicit def genCommutativeSemigroup[T](implicit
implicit def autoDerivationCommutativeSemigroup[T](implicit
lp: shapeless.LowPriority
): CommutativeSemigroup[T] =
macro CatsMacros.genCommutativeSemigroupMacro[T]
macro CatsMacros.autoDerivationCommutativeSemigroup[T]
// Monoid <: Semigroup
implicit def genMonoid[T](implicit lp: shapeless.LowPriority): Monoid[T] =
macro CatsMacros.genMonoidMacro[T]
implicit def autoDerivationMonoid[T](implicit lp: shapeless.LowPriority): Monoid[T] =
macro CatsMacros.autoDerivationMonoid[T]
}

trait LowPriority4Implicits extends LowPriority5Implicits {
// Band <: Semigroup
implicit def genBand[T](implicit lp: shapeless.LowPriority): Band[T] =
macro CatsMacros.genBandMacro[T]
implicit def autoDerivationBand[T](implicit lp: shapeless.LowPriority): Band[T] =
macro CatsMacros.autoDerivationBand[T]
}

trait LowPriority5Implicits {
implicit def genSemigroup[T](implicit lp: shapeless.LowPriority): Semigroup[T] =
macro CatsMacros.genSemigroupMacro[T]
implicit def autoDerivationSemigroup[T](implicit lp: shapeless.LowPriority): Semigroup[T] =
macro CatsMacros.autoDerivationSemigroup[T]
}
47 changes: 0 additions & 47 deletions cats/src/main/scala-3/magnolify/cats/CatsImplicits.scala

This file was deleted.

36 changes: 26 additions & 10 deletions cats/src/main/scala-3/magnolify/cats/CatsMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.Show
import cats.kernel.*

import scala.deriving.Mirror
import scala.util.NotGiven

// set implicit priority to avoid conflicts
// see: https://typelevel.org/cats/guidelines.html#implicit-instance-priority
Expand All @@ -29,33 +30,48 @@ import scala.deriving.Mirror
trait AutoDerivation extends LowPriority0Implicits

trait LowPriority0Implicits extends LowPriority1Implicits:
inline implicit def genShow[T](using Mirror.Of[T]): Show[T] = ShowDerivation.gen[T]
inline implicit def autoDerivationShow[T](using Mirror.Of[T]): Show[T] =
ShowDerivation.gen[T]
// CommutativeGroup <: Group | CommutativeMonoid
inline implicit def genCommutativeGroup[T](using Mirror.Of[T]): CommutativeGroup[T] =
inline implicit def autoDerivationCommutativeGroup[T](using
Mirror.Of[T]
): CommutativeGroup[T] =
CommutativeGroupDerivation.gen[T]
// Hash <: Eq
inline implicit def genHash[T](using Mirror.Of[T]): Hash[T] = HashDerivation.gen[T]
inline implicit def autoDerivationHash[T](using Mirror.Of[T]): Hash[T] =
HashDerivation.gen[T]

trait LowPriority1Implicits extends LowPriority2Implicits:
inline implicit def genEq[T](using Mirror.Of[T]): Eq[T] = EqDerivation.gen[T]
inline implicit def autoDerivationEq[T](using Mirror.Of[T]): Eq[T] =
EqDerivation.gen[T]
// Group <: Monoid
inline implicit def genGroup[T](using Mirror.Of[T]): Group[T] = GroupDerivation.gen[T]
inline implicit def autoDerivationGroup[T](using Mirror.Of[T]): Group[T] =
GroupDerivation.gen[T]

trait LowPriority2Implicits extends LowPriority3Implicits:
// CommutativeMonoid <: Monoid | CommutativeSemigroup
inline implicit def genCommutativeMonoid[T](using Mirror.Of[T]): CommutativeMonoid[T] =
inline implicit def autoDerivationCommutativeMonoid[T](using
Mirror.Of[T]
): CommutativeMonoid[T] =
CommutativeMonoidDerivation.gen[T]

trait LowPriority3Implicits extends LowPriority4Implicits:
// CommutativeSemigroup <: Semigroup
inline implicit def genCommutativeSemigroup[T](using Mirror.Of[T]): CommutativeSemigroup[T] =
inline implicit def autoDerivationCommutativeSemigroup[T](using
Mirror.Of[T]
): CommutativeSemigroup[T] =
CommutativeSemigroupDerivation.gen[T]
// Monoid <: Semigroup
inline implicit def genMonoid[T](using Mirror.Of[T]): Monoid[T] = MonoidDerivation.gen[T]
inline implicit def autoDerivationMonoid[T](using Mirror.Of[T]): Monoid[T] =
MonoidDerivation.gen[T]

trait LowPriority4Implicits extends LowPriority5Implicits:
// Band <: Semigroup
inline implicit def genBand[T](using Mirror.Of[T]): Band[T] = BandDerivation.gen[T]
inline implicit def autoDerivationBand[T](using Mirror.Of[T]): Band[T] =
BandDerivation.gen[T]

trait LowPriority5Implicits:
inline implicit def genSemigroup[T](using Mirror.Of[T]): Semigroup[T] = SemigroupDerivation.gen[T]
inline implicit def autoDerivationSemigroup[T](using
Mirror.Of[T]
): Semigroup[T] =
SemigroupDerivation.gen[T]
2 changes: 1 addition & 1 deletion cats/src/main/scala/magnolify/cats/auto/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package magnolify.cats

package object auto extends CatsImplicits with AutoDerivation
package object auto extends AutoDerivation
Loading

0 comments on commit cf5c497

Please sign in to comment.