Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed attempt to resolve the warnings via implicit priorities #617

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ciRelease := {
val versions = new {
val scala212 = "2.12.20"
val scala213 = "2.13.15"
val scala3 = "3.3.4"
val scala3 = "3.5.1"

// Which versions should be cross-compiled for publishing
val scalas = List(scala212, scala213, scala3)
Expand Down Expand Up @@ -84,7 +84,9 @@ val settings = Seq(
// format: off
"-encoding", "UTF-8",
"-rewrite",
"-source", "3.3-migration",
//"-source", "3.4-migration",
"-source", "3.6",
//"-source", "3.3-migration",
// format: on
"-unchecked",
"-deprecation",
Expand All @@ -102,7 +104,7 @@ val settings = Seq(
"-Wunused:implicits",
"-Wunused:params",
"-Wvalue-discard",
"-Xfatal-warnings",
//"-Xfatal-warnings",
"-Xcheck-macros",
"-Ykind-projector:underscores"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private[compiletime] trait ExprsPlatform extends Exprs { this: DefinitionsPlatfo
'{ scala.IArray.apply[A](${ quoted.Varargs[A](args.toSeq) }*)(using ${ summonImplicitUnsafe[ClassTag[A]] }) }

def map[A: Type, B: Type](iarray: Expr[IArray[A]])(fExpr: Expr[A => B]): Expr[scala.IArray[B]] =
'{ ${ resetOwner(iarray) }.map(${ resetOwner(fExpr) })(${ summonImplicitUnsafe[ClassTag[B]] }) }
'{ ${ resetOwner(iarray) }.map(${ resetOwner(fExpr) })(using ${ summonImplicitUnsafe[ClassTag[B]] }) }

def to[A: Type, C: Type](iarray: Expr[IArray[A]])(
factoryExpr: Expr[scala.collection.compat.Factory[A, C]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private[compiletime] trait TypesPlatform extends Types { this: DefinitionsPlatfo
// $COVERAGE-OFF$should never happen unless we messed up
case out =>
assertionFailed(
s"Constructor of ${Type.prettyPrint(fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: $out"
s"Constructor of ${Type.prettyPrint(using fromUntyped[Any](tpe))} has unrecognized/unsupported format of type: $out"
)
// $COVERAGE-ON$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ trait IterableOrArraysPlatform extends IterableOrArrays { this: DefinitionsPlatf
new IterableOrArray[M, Inner] {
def factory: Expr[Factory[Inner, M]] =
'{
io.scalaland.chimney.integrations.FactoryCompat.iarrayFactory[Inner](${
Expr.summonImplicitUnsafe[ClassTag[Inner]]
})
io.scalaland.chimney.integrations.FactoryCompat.iarrayFactory[Inner](using
${
Expr.summonImplicitUnsafe[ClassTag[Inner]]
}
)
}.asExprOf[Factory[Inner, M]]

def iterator(m: Expr[M]): Expr[Iterator[Inner]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ trait ValueClassesPlatform extends ValueClasses { this: DefinitionsPlatform =>
assert(
Argument <:< Inner,
s"Wrapper/AnyVal ${Type.prettyPrint[A]} only property's type (${Type
.prettyPrint(Argument)}) was expected to be the same as only constructor argument's type (${Type
.prettyPrint(Inner)})"
.prettyPrint(using Argument)}) was expected to be the same as only constructor argument's type (${Type
.prettyPrint(using Inner)})"
)
Some(
Existential[WrapperClass[A, *], Inner](
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.scalaland.chimney.internal.compiletime

private[compiletime] trait Existentials { this: Types with Exprs =>
private[compiletime] trait Existentials { this: Types & Exprs =>

/** Represents value with some existential type `t` both for `Type[t]` as well as `F[t]`.
*
Expand All @@ -20,7 +20,7 @@ private[compiletime] trait Existentials { this: Types with Exprs =>
val value: F[Underlying]

def mapK[G[_]](f: Type[Underlying] => F[Underlying] => G[Underlying]): Bounded[L, U, G] =
Bounded[L, U, G, Underlying](f(Underlying)(value))(Underlying)
Bounded[L, U, G, Underlying](f(Underlying)(value))(using Underlying)
}
object Bounded {
def apply[L, U >: L, F[_ >: L <: U], A >: L <: U: Type](value: F[A]): Bounded[L, U, F] =
Expand Down Expand Up @@ -63,9 +63,9 @@ private[compiletime] trait Existentials { this: Types with Exprs =>
def apply[U, A <: U](implicit A: Type[A]): Bounded[Nothing, U] = Existential.Bounded[Nothing, U, Type, A](A)
}

def apply[A](implicit A: Type[A]): ExistentialType = Existential[Type, A](A)(A)
def apply[A](implicit A: Type[A]): ExistentialType = Existential[Type, A](A)(using A)

def prettyPrint(existentialType: ExistentialType): String = Type.prettyPrint(existentialType.Underlying)
def prettyPrint(existentialType: ExistentialType): String = Type.prettyPrint(using existentialType.Underlying)
}

/** Convenient utility to represent `Expr[?]` with erased inner type with accompanying `Type[?]` of the same `?`. */
Expand All @@ -74,7 +74,7 @@ private[compiletime] trait Existentials { this: Types with Exprs =>

def apply[A: Type](expr: Expr[A]): ExistentialExpr = Existential[Expr, A](expr)

def withoutType[A](expr: Expr[A]): ExistentialExpr = apply(expr)(Expr.typeOf(expr))
def withoutType[A](expr: Expr[A]): ExistentialExpr = apply(expr)(using Expr.typeOf(expr))

def prettyPrint(existentialExpr: ExistentialExpr): String = Expr.prettyPrint(existentialExpr.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private[compiletime] trait Types { this: (Existentials & Results) =>
.unapply(S)
.getOrElse {
// $COVERAGE-OFF$should never happen unless someone mess around with type-level representation
assertionFailed(s"Invalid string literal type: ${prettyPrint(S)}")
assertionFailed(s"Invalid string literal type: ${prettyPrint(using S)}")
// $COVERAGE-ON$
}
.value
Expand All @@ -199,12 +199,12 @@ private[compiletime] trait Types { this: (Existentials & Results) =>

def isTuple: Boolean = Type.isTuple(tpe)
def isAnyVal: Boolean = tpe <:< Type.AnyVal
def isOption: Boolean = tpe <:< Type.Option(Type.Any)
def isEither: Boolean = tpe <:< Type.Either(Type.Any, Type.Any)
def isLeft: Boolean = tpe <:< Type.Either.Left(Type.Any, Type.Any)
def isRight: Boolean = tpe <:< Type.Either.Right(Type.Any, Type.Any)
def isIterable: Boolean = tpe <:< Type.Iterable(Type.Any)
def isMap: Boolean = tpe <:< Type.Map(Type.Any, Type.Any)
def isOption: Boolean = tpe <:< Type.Option(using Type.Any)
def isEither: Boolean = tpe <:< Type.Either(using Type.Any, Type.Any)
def isLeft: Boolean = tpe <:< Type.Either.Left(using Type.Any, Type.Any)
def isRight: Boolean = tpe <:< Type.Either.Right(using Type.Any, Type.Any)
def isIterable: Boolean = tpe <:< Type.Iterable(using Type.Any)
def isMap: Boolean = tpe <:< Type.Map(using Type.Any, Type.Any)

def as_?? : ?? = ExistentialType[A](tpe)
def as_>?<[L <: A, U >: A]: L >?< U = ExistentialType.Bounded[L, U, A](tpe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ trait ProductTypes { this: Definitions =>
final case class Extraction[From](extraction: Getters[From])
object Extraction {
def unapply[From](From: Type[From]): Option[Getters[From]] =
ProductType.parseExtraction(From).map(getters => getters.extraction)
ProductType.parseExtraction(using From).map(getters => getters.extraction)
}

final case class Parameter[A](targetType: Parameter.TargetType, defaultValue: Option[Expr[A]])
Expand All @@ -62,7 +62,7 @@ trait ProductTypes { this: Definitions =>
/** When constructing, value will be passed as setter argument */
final case class SetterParameter(returnedType: ??) extends TargetType {
override def toString: String =
s"SetterParameter(returnedType = ${Type.prettyPrint(returnedType.Underlying)})"
s"SetterParameter(returnedType = ${Type.prettyPrint(using returnedType.Underlying)})"
}
}
}
Expand All @@ -76,7 +76,7 @@ trait ProductTypes { this: Definitions =>
final case class Constructor[To](parameters: Parameters, constructor: Arguments => Expr[To])
object Constructor {
def unapply[To](To: Type[To]): Option[(Parameters, Arguments => Expr[To])] =
ProductType.parseConstructor(To).map(constructor => constructor.parameters -> constructor.constructor)
ProductType.parseConstructor(using To).map(constructor => constructor.parameters -> constructor.constructor)

def exprAsInstanceOfMethod[To: Type](args: List[ListMap[String, ??]])(expr: Expr[Any]): Constructor[To] =
ProductType.exprAsInstanceOfMethod[To](args)(expr)
Expand Down Expand Up @@ -109,7 +109,7 @@ trait ProductTypes { this: Definitions =>
final def parse[A: Type]: Option[Product[A]] = parseExtraction[A].zip(parseConstructor[A]).headOption.map {
case (getters, constructor) => Product(getters, constructor)
}
final def unapply[A](tpe: Type[A]): Option[Product[A]] = parse(tpe)
final def unapply[A](tpe: Type[A]): Option[Product[A]] = parse(using tpe)

def exprAsInstanceOfMethod[A: Type](args: List[ListMap[String, ??]])(expr: Expr[Any]): Product.Constructor[A]

Expand Down Expand Up @@ -145,7 +145,7 @@ trait ProductTypes { this: Definitions =>
// $COVERAGE-OFF$should never happen unless we messed up
assertionFailed(
s"Constructor of ${Type.prettyPrint[A]} expected expr for parameter $param of type ${Type
.prettyPrint[param.Underlying]}, instead got ${Expr.prettyPrint(argument.value)} ${Type.prettyPrint(argument.Underlying)}"
.prettyPrint[param.Underlying]}, instead got ${Expr.prettyPrint(argument.value)} ${Type.prettyPrint(using argument.Underlying)}"
)
// $COVERAGE-ON$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait SealedHierarchies { this: Definitions =>
protected trait SealedHierarchyModule { this: SealedHierarchy.type =>

def parse[A: Type]: Option[Enum[A]]
final def unapply[A](tpe: Type[A]): Option[Enum[A]] = parse(tpe)
final def unapply[A](tpe: Type[A]): Option[Enum[A]] = parse(using tpe)

def isJavaEnum[A: Type]: Boolean

Expand All @@ -28,6 +28,6 @@ trait SealedHierarchies { this: Definitions =>

implicit class SealedHierarchyOps[A](private val tpe: Type[A]) {

def isSealed: Boolean = SealedHierarchy.isSealed(tpe)
def isSealed: Boolean = SealedHierarchy.isSealed(using tpe)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ trait SingletonTypes { this: (Definitions & ProductTypes) =>
case _ => None
}
}
final def unapply[A](tpe: Type[A]): Option[Singleton[A]] = parse(tpe)
final def unapply[A](tpe: Type[A]): Option[Singleton[A]] = parse(using tpe)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ValueClasses { this: Definitions =>
protected trait WrapperClassTypeModule { this: WrapperClassType.type =>

def parse[A: Type]: Option[Existential[WrapperClass[A, *]]]
final def unapply[A](tpe: Type[A]): Option[Existential[WrapperClass[A, *]]] = parse(tpe)
final def unapply[A](tpe: Type[A]): Option[Existential[WrapperClass[A, *]]] = parse(using tpe)
}

protected object ValueClassType {
Expand All @@ -45,6 +45,6 @@ trait ValueClasses { this: Definitions =>
}
}
else None
def unapply[A](tpe: Type[A]): Option[Existential.UpperBounded[AnyVal, ValueClass[A, *]]] = parse(tpe)
def unapply[A](tpe: Type[A]): Option[Existential.UpperBounded[AnyVal, ValueClass[A, *]]] = parse(using tpe)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.scalaland.chimney.internal.compiletime.fp
trait ApplicativeTraverse[F[_]] extends Traverse[F] with Applicative[F] {

override def map[A, B](fa: F[A])(f: A => B): F[B] =
traverse[Applicative.Id, A, B](fa)(f)(Applicative.IdentityApplicative)
traverse[Applicative.Id, A, B](fa)(f)(using Applicative.IdentityApplicative)
}
object ApplicativeTraverse {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ trait Traverse[F[_]] extends Functor[F] {
def parTraverse[G[_]: Parallel, A, B](fa: F[A])(f: A => G[B]): G[F[B]]

override def map[A, B](fa: F[A])(f: A => B): F[B] =
traverse[Applicative.Id, A, B](fa)(f)(Applicative.IdentityApplicative)
traverse[Applicative.Id, A, B](fa)(f)(using Applicative.IdentityApplicative)
}
object Traverse {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private[chimney] class DslMacroUtils()(using quotes: Quotes) {
Type.of[runtime.ArgumentLists.List[Head, Tail]]
}

ApplyParams(head, tail)
ApplyParams(using head, tail)
}

private def constructArgumentListType(
Expand All @@ -273,7 +273,7 @@ private[chimney] class DslMacroUtils()(using quotes: Quotes) {
Type.of[runtime.ArgumentList.Argument[ParamName, ParamType, Args]]
}

ApplyParam(
ApplyParam(using
ConstantType(StringConstant(name)).asType.asInstanceOf[Type[String]],
tpe.tpe.asType.asInstanceOf[Type[Any]],
args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ object PartialTransformer extends PartialTransformerCompanionPlatform {
}

/** @since 0.8.0 */
object AutoDerived extends PartialTransformerAutoDerivedCompanionPlatform {
object AutoDerived extends AutoDerivedLowPriorityImplicits1
private[chimney] trait AutoDerivedLowPriorityImplicits1 extends PartialTransformerAutoDerivedCompanionPlatform {
this: AutoDerived.type =>

implicit def liftTotal[From, To](implicit total: Transformer[From, To]): AutoDerived[From, To] =
(src: From, failFast: Boolean) => partial.Result.fromCatching(total.transform(src))
Expand Down
5 changes: 4 additions & 1 deletion chimney/src/main/scala/io/scalaland/chimney/Patcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ object Patcher extends PatcherCompanionPlatform {
}

/** @since 0.8.0 */
object AutoDerived extends PatcherAutoDerivedCompanionPlatform
object AutoDerived extends AutoDerivedLowPriorityImplicits1
private[chimney] trait AutoDerivedLowPriorityImplicits1 extends PatcherAutoDerivedCompanionPlatform {
this: AutoDerived.type =>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ object Transformer extends TransformerCompanionPlatform {
}

/** @since 0.8.0 */
object AutoDerived extends TransformerAutoDerivedCompanionPlatform
object AutoDerived extends AutoDerivedLowPriorityImplicits1
private[chimney] trait AutoDerivedLowPriorityImplicits1 extends AutoDerivedLowPriorityImplicits2 {
this: AutoDerived.type =>
}
private[chimney] trait AutoDerivedLowPriorityImplicits2 extends TransformerAutoDerivedCompanionPlatform {
this: AutoDerived.type =>
}
}
// extended by TransformerCompanionPlatform
private[chimney] trait TransformerLowPriorityImplicits1 extends TransformerLowPriorityImplicits2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ private[compiletime] trait Contexts { this: Derivation =>
.asInstanceOf[this.type]

override def toString: String =
s"PatcherContext[A = ${Type.prettyPrint(A)}, Patch = ${Type
.prettyPrint(Patch)}](obj = ${Expr.prettyPrint(obj)}, patch = ${Expr.prettyPrint(patch)})($config)"
s"PatcherContext[A = ${Type.prettyPrint(using A)}, Patch = ${Type
.prettyPrint(using Patch)}](obj = ${Expr.prettyPrint(obj)}, patch = ${Expr.prettyPrint(patch)})($config)"
}
object PatcherContext {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private[compiletime] trait Derivation
if (ctx.config.flags.ignoreRedundantPatcherFields)
DerivationResult.pure(None)
else
DerivationResult.patcherError(PatchFieldNotFoundInTargetObj(patchFieldName, Type.prettyPrint(ctx.A)))
DerivationResult.patcherError(PatchFieldNotFoundInTargetObj(patchFieldName, Type.prettyPrint(using ctx.A)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ private[compiletime] trait Configurations { this: Derivation =>
case _ => false
}

override def toString: String = s".matching[${Type.prettyPrint(tpe.Underlying)}]"
override def toString: String = s".matching[${Type.prettyPrint(using tpe.Underlying)}]"
}
final case class SourceMatching(tpe: ??) extends Segment {
override def equals(obj: Any): Boolean = obj match {
case Matching(tpe2) => tpe.Underlying =:= tpe2.Underlying
case _ => false
}

override def toString: String = s" if src.isInstanceOf[${Type.prettyPrint(tpe.Underlying)}]"
override def toString: String = s" if src.isInstanceOf[${Type.prettyPrint(using tpe.Underlying)}]"
}
case object EveryItem extends Segment {
override def toString: String = ".everyItem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private[compiletime] trait Contexts { this: Derivation =>
): B = forTotal(this)

override def toString: String =
s"ForTotal[From = ${Type.prettyPrint(From)}, To = ${Type.prettyPrint(To)}](src = ${Expr.prettyPrint(src)})($config)"
s"ForTotal[From = ${Type.prettyPrint(using From)}, To = ${Type.prettyPrint(using To)}](src = ${Expr.prettyPrint(src)})($config)"
}

object ForTotal {
Expand All @@ -126,7 +126,7 @@ private[compiletime] trait Contexts { this: Derivation =>
) extends TransformationContext[From, To] {

final type Target = partial.Result[To]
val Target = ChimneyType.PartialResult(To)
val Target = ChimneyType.PartialResult(using To)

override def fold[B](
forTotal: TransformationContext.ForTotal[From, To] => B
Expand All @@ -135,8 +135,8 @@ private[compiletime] trait Contexts { this: Derivation =>
): B = forPartial(this)

override def toString: String =
s"ForPartial[From = ${Type.prettyPrint(From)}, To = ${Type
.prettyPrint(To)}](src = ${Expr.prettyPrint(src)}, failFast = ${Expr.prettyPrint(failFast)})($config)"
s"ForPartial[From = ${Type.prettyPrint(using From)}, To = ${Type
.prettyPrint(using To)}](src = ${Expr.prettyPrint(src)}, failFast = ${Expr.prettyPrint(failFast)})($config)"
}

object ForPartial {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio
DerivationResult.log {
val gettersStr = fromExtractors
.map { case (k, v) =>
s"`$k`: ${Type.prettyPrint(v.Underlying)} (${v.value.sourceType}, ${if (!v.value.isInherited) "declared"
s"`$k`: ${Type.prettyPrint(using v.Underlying)} (${v.value.sourceType}, ${if (!v.value.isInherited) "declared"
else "inherited"})"
}
.mkString(", ")
val constructorStr = parameters
.map { case (k, v) =>
s"`$k`: ${Type.prettyPrint(v.Underlying)} (${v.value.targetType}, default = ${v.value.defaultValue
s"`$k`: ${Type.prettyPrint(using v.Underlying)} (${v.value.targetType}, default = ${v.value.defaultValue
.map(a => Expr.prettyPrint(a))})"
}
.mkString(", ")
Expand Down Expand Up @@ -688,7 +688,7 @@ private[compiletime] trait TransformProductToProductRuleModule { this: Derivatio
},
// Here, we're building:
// '{ if (allerrors == null) $ifBlock else $elseBock }
Expr.ifElse[partial.Result[ToOrPartialTo]](allerrors eqExpr Expr.Null) {
Expr.ifElse[partial.Result[ToOrPartialTo]](allerrors `eqExpr` Expr.Null) {
// Here, we're building:
// '{ partial.Result.Value(${ constructor }) } // using res1.asInstanceOf[partial.Result.Value[Tpe]].value, ...
ChimneyExpr.PartialResult
Expand Down
Loading
Loading