Skip to content
Merged
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
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ThisBuild / organizationName := "arainko"
ThisBuild / startYear := Some(2023)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(tlGitHubDev("arainko", "Aleksander Rainko"))
ThisBuild / scalaVersion := "3.3.6"
ThisBuild / scalaVersion := "3.3.7"
ThisBuild / tlSitePublishBranch := Some("series/0.2.x")

ThisBuild / semanticdbEnabled := true
Expand Down Expand Up @@ -47,8 +47,8 @@ lazy val ducktape =
.in(file("ducktape"))
.settings(
scalacOptions ++= List("-deprecation", "-Wunused:all", "-Ykind-projector:underscores", "-Xcheck-macros"),
Test / scalacOptions --= List("-deprecation"),
Test / scalacOptions ++= List("-Werror", "-Wconf:cat=deprecation:s"),
Test / scalacOptions --= List("-deprecation", "-Wunused:all"),
Test / scalacOptions ++= List("-Werror", "-Wconf:cat=deprecation:s", "-Wunused:imports"),
libraryDependencies += "org.scalameta" %%% "munit" % "1.2.1" % Test
)
.nativeSettings(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.arainko.ducktape

import io.github.arainko.ducktape
import io.github.arainko.ducktape.Transformer.Derived.FromFunction
import io.github.arainko.ducktape.internal.{ FallibleTransformations, TotalTransformations }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private[ducktape] object ConfigInstructionRefiner {
case inst @ Instruction.Static(_, _, config, _) =>
config match
case cfg: (Const | CaseComputed | FieldComputed | FieldComputedDeep | FieldReplacement) => inst.copy(config = cfg)
case fallible: (FallibleConst | FallibleFieldComputed | FallibleFieldComputedDeep | FallibleCaseComputed) => None
case _: (FallibleConst | FallibleFieldComputed | FallibleFieldComputedDeep | FallibleCaseComputed) => None
case inst: (Instruction.Dynamic | Instruction.Bulk | Instruction.Regional | Instruction.Failed) => inst

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.arainko.ducktape.internal

import io.github.arainko.ducktape.*

import scala.annotation.nowarn
import scala.quoted.*

import Configuration.*
Expand All @@ -12,6 +13,8 @@ private[ducktape] sealed trait ConfigParser[+F <: Fallible] {
def apply(using Quotes, Context): PartialFunction[(Priority, quotes.reflect.Term), Instruction[F] | ParsedFlag]
}

@nowarn("msg=unused pattern variable")
@nowarn("msg=unused local definition")
private[ducktape] object ConfigParser {
val total = NonEmptyList(Total)

Expand Down Expand Up @@ -486,8 +489,6 @@ private[ducktape] object ConfigParser {

private object DeprecatedFallibleConfig {
def unapply[F[+x]: Type](using Quotes)(prioAndTerm: (Priority, quotes.reflect.Term)) = {
import quotes.reflect.*

val (prio, expr) = prioAndTerm

PartialFunction.condOpt(expr.asExpr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private[ducktape] object Configuration {
Quotes
): Configuration[Nothing] | plan.type =
plan.dest.tpe match {
case tpe @ '[Option[a]] => Configuration.Const('{ None }, tpe)
case tpe @ '[Option[?]] => Configuration.Const('{ None }, tpe)
case _ => plan
}

Expand Down Expand Up @@ -126,7 +126,7 @@ private[ducktape] object Configuration {
parsers: NonEmptyList[ConfigParser[F]]
)(using Quotes, Context): (List[Instruction[F]], PlanFlags) = {
import quotes.reflect.*
def fallback(term: quotes.reflect.Term, priority: Priority) =
def fallback(term: quotes.reflect.Term) =
Configuration.Instruction.Failed(
Path.empty(Type.of[Nothing]),
Side.Dest,
Expand All @@ -144,7 +144,7 @@ private[ducktape] object Configuration {
parser
.applyOrElse(
(Priority.of(priority), expr.asTerm),
(priority, expr) => fallback(expr, Priority.of(priority))
(_, expr) => fallback(expr)
)
.match {
case instruction: Instruction[F] => Left(instruction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private[ducktape] object Constructor {
val (repr, constructor, tpeArgs) =
tpe match {
case AppliedType(repr, reprArguments) => (repr, repr.typeSymbol.primaryConstructor, reprArguments)
case notApplied => (tpe, tpe.typeSymbol.primaryConstructor, Nil)
case _ => (tpe, tpe.typeSymbol.primaryConstructor, Nil)
}

// workaround for invoking constructors of singleton which in turn actually create new instances of singletons!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ private[ducktape] object ErroneousnessRefiner {
protected def foldOver(plan: Plan[Erroneous, Fallible], accumulator: List[Plan.Error]): List[Plan.Error] =
plan match {
case error: Plan.Error => error :: accumulator
case other => accumulator
case _ => accumulator
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import scala.util.boundary.Label
private[ducktape] object FallibilityRefiner {
def run[E <: Erroneous](plan: Plan[E, Fallible]): Plan[E, Nothing] | None.type =
recurse(plan) match
case None => None
case b: Unit => plan.asInstanceOf[Plan[E, Nothing]]
case None => None
case () => plan.asInstanceOf[Plan[E, Nothing]]

private def recurse[E <: Erroneous](plan: Plan[E, Fallible]): None.type | Unit =
boundary[None.type | Unit]:
Expand All @@ -30,15 +30,15 @@ private[ducktape] object FallibilityRefiner {

case Configured(source, dest, config, _) =>
config match
case Configuration.Const(value, tpe) => ()
case Configuration.CaseComputed(tpe, function) => ()
case Configuration.FieldComputed(tpe, function) => ()
case Configuration.FieldComputedDeep(tpe, srcTpe, function) => ()
case Configuration.FieldReplacement(source, _, name, tpe) => ()
case Configuration.FallibleConst(value, tpe) => boundary.break(None)
case Configuration.FallibleFieldComputed(tpe, function) => boundary.break(None)
case Configuration.FallibleFieldComputedDeep(tpe, srcTpe, function) => boundary.break(None)
case Configuration.FallibleCaseComputed(tpe, function) => boundary.break(None)
case Configuration.Const(value, _) => ()
case Configuration.CaseComputed(_, function) => ()
case Configuration.FieldComputed(_, function) => ()
case Configuration.FieldComputedDeep(_, _, function) => ()
case Configuration.FieldReplacement(source, _, name, _) => ()
case Configuration.FallibleConst(value, _) => boundary.break(None)
case Configuration.FallibleFieldComputed(_, function) => boundary.break(None)
case Configuration.FallibleFieldComputedDeep(_, _, function) => boundary.break(None)
case Configuration.FallibleCaseComputed(_, function) => boundary.break(None)

case BetweenProductFunction(source, dest, argPlans) =>
evaluate(argPlans.map((_, fieldPlan) => fieldPlan.plan))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.arainko.ducktape.internal
import io.github.arainko.ducktape.internal.Summoner.UserDefined.{ FallibleTransformer, TotalTransformer }
import io.github.arainko.ducktape.{ Mode, Transformer }

import scala.annotation.nowarn
import scala.collection.Factory
import scala.collection.immutable.VectorMap
import scala.quoted.*
Expand All @@ -20,7 +21,6 @@ private[ducktape] object FalliblePlanInterpreter {
value: Expr[Any],
F: TransformationMode[F]
)(using toplevelValue: Expr[A])(using Quotes): Value[F] = {
import quotes.reflect.*

FallibilityRefiner.run(plan) match
case plan: Plan[Nothing, Nothing] =>
Expand All @@ -33,13 +33,13 @@ private[ducktape] object FalliblePlanInterpreter {
config match
case cfg @ Configuration.Const(_, _) =>
Value.Unwrapped(PlanInterpreter.evaluateConfig(cfg, value))
case cfg @ Configuration.CaseComputed(tpe, function) =>
case cfg @ Configuration.CaseComputed(_, function) =>
Value.Unwrapped(PlanInterpreter.evaluateConfig(cfg, value))
case cfg @ Configuration.FieldComputed(tpe, function) =>
case cfg @ Configuration.FieldComputed(_, function) =>
Value.Unwrapped(PlanInterpreter.evaluateConfig(cfg, value))
case cfg @ Configuration.FieldComputedDeep(tpe, srcTpe, function) =>
case cfg @ Configuration.FieldComputedDeep(_, _, function) =>
Value.Unwrapped(PlanInterpreter.evaluateConfig(cfg, value))
case cfg @ Configuration.FieldReplacement(source, _, name, tpe) =>
case cfg @ Configuration.FieldReplacement(source, _, name, _) =>
Value.Unwrapped(PlanInterpreter.evaluateConfig(cfg, value))
case Configuration.FallibleConst(value, tpe) =>
tpe match {
Expand All @@ -52,7 +52,7 @@ private[ducktape] object FalliblePlanInterpreter {
Value.Wrapped('{ $function($toplevelValue) }.asExprOf[F[tpe]])
}

case Configuration.FallibleFieldComputedDeep(tpe, srcTpe, function) =>
case Configuration.FallibleFieldComputedDeep(tpe, _, function) =>
tpe match {
case '[tpe] =>
Value.Wrapped('{ $function($value) }.asExprOf[F[tpe]])
Expand Down Expand Up @@ -167,8 +167,7 @@ private[ducktape] object FalliblePlanInterpreter {
)(using $f)
})
}

}
}: @nowarn("msg=unused local definition")

case Plan.BetweenSingletons(source, dest) =>
Value.Unwrapped(dest.value)
Expand Down Expand Up @@ -235,7 +234,6 @@ private[ducktape] object FalliblePlanInterpreter {
value: Expr[Any],
F: TransformationMode[F]
)(construct: ProductConstructor)(using quotes: Quotes, toplevelValue: Expr[A]) = {
import quotes.reflect.*

val (unwrapped, wrapped) =
plans.zipWithIndex.partitionMap {
Expand Down Expand Up @@ -276,7 +274,6 @@ private[ducktape] object FalliblePlanInterpreter {
value: Expr[Any],
F: TransformationMode[F]
)(construct: ProductConstructor)(using quotes: Quotes, toplevelValue: Expr[A]) = {
import quotes.reflect.*

def handleVectorMap(sourceStruct: Structure.Product, fieldPlans: VectorMap[String, FieldPlan[Nothing, Fallible]])(using
Quotes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ private[ducktape] object FallibleTransformations {
function: Expr[Func],
F: Expr[Mode[F]]
)(using Quotes): Expr[F[Any]] = {
import quotes.reflect.*

given Context.PossiblyFallible[F](
WrapperType.create[F],
TransformationSite.Transformation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private[ducktape] object Function {
List
.unfold(Type.of[Args].repr) {
case Refinement(leftover, name, tpe) => Some(name -> tpe.asType, leftover)
case other => None
case _ => None
}
.reverse
.to(VectorMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private[ducktape] final case class Path(root: Type[?], segments: Vector[Path.Seg

def prepended(segment: Path.Segment): Path = self.copy(segments = segments.prepended(segment))

def narrowedCurrentTpe(using Quotes): Type[?] =
def narrowedCurrentTpe: Type[?] =
segments.lastOption.fold(root)(_.tpe)

// deliberately use something that requires a total function so that when a new Path.Segment is declared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ private[ducktape] object PathSelector {
)
),
_,
Typed(term, tpe @ Applied(TypeIdent("Elem"), _))
Typed(_, tpe @ Applied(TypeIdent("Elem"), _))
) =>
Logger.debug(s"Matching positional tuple .apply($index)")

recurse(acc.prepended(Path.Segment.TupleElement(tpe.tpe.widen.simplified.asType, index)), tree)

case tr @ Inlined(
case Inlined(
Some(
Apply(
Apply(TypeApply(Select(Ident("NamedTuple"), "apply"), List(namesTpe, _)), List(tree)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ private[ducktape] object PlanConfigurer {
)(using Quotes): Plan[Erroneous, F] = {
def traverseBetweenNotFallible(
parent: BetweenFallibleNonFallible[Erroneous],
plan: Plan[Erroneous, Nothing],
tail: List[Path.Segment]
) =
ConfigInstructionRefiner.run(config) match
Expand All @@ -50,7 +49,7 @@ private[ducktape] object PlanConfigurer {
parent.update(recurse(_, tail, parent, config))

case parent @ BetweenFallibleNonFallible(source, dest, plan) if config.side.isSource =>
traverseBetweenNotFallible(parent, plan, tail)
traverseBetweenNotFallible(parent, tail)

case parent @ BetweenFallibles(source, dest, mode, plan) if config.side.isSource =>
parent.update(recurse(_, tail, parent, config))
Expand All @@ -66,13 +65,13 @@ private[ducktape] object PlanConfigurer {
current match {
// passthrough BetweenFallibles, the dest is just a normal field in this case
case parent @ BetweenFallibleNonFallible(source, dest, plan) if config.side.isDest =>
traverseBetweenNotFallible(parent, plan, segments)
traverseBetweenNotFallible(parent, segments)

// passthrough BetweenFallibles, the dest is just a normal field in this case
case parent @ BetweenFallibles(source, dest, mode, plan) if config.side.isDest =>
parent.update(recurse(_, tail, parent, config))

case parent @ BetweenProducts(sourceTpe, destTpe, fieldPlans) =>
case parent @ BetweenProducts(_, _, fieldPlans) =>
parent.updateOrElse(segment.name)(
recurse(_, tail, parent, config),
Plan.Error.from(parent, ErrorMessage.InvalidFieldAccessor(segment.name, config.span), None)
Expand All @@ -90,7 +89,7 @@ private[ducktape] object PlanConfigurer {
Plan.Error.from(parent, ErrorMessage.InvalidFieldAccessor(segment.name, config.span), None)
)

case parent @ BetweenProductFunction(sourceTpe, destTpe, argPlans) =>
case parent @ BetweenProductFunction(_, _, argPlans) =>
parent.updateOrElse(segment.name)(
recurse(_, tail, parent, config),
Plan.Error.from(parent, ErrorMessage.InvalidArgAccessor(segment.name, config.span), None)
Expand Down Expand Up @@ -120,7 +119,7 @@ private[ducktape] object PlanConfigurer {
current match {
// passthrough BetweenFallibles, the dest is just a tuple elem in this case
case parent @ BetweenFallibleNonFallible(source, dest, plan) if config.side.isDest =>
traverseBetweenNotFallible(parent, plan, segments)
traverseBetweenNotFallible(parent, segments)

// passthrough BetweenFallibles, the dest is just a tuple elem in this case
case parent @ BetweenFallibles(source, dest, mode, plan) if config.side.isDest =>
Expand All @@ -147,7 +146,7 @@ private[ducktape] object PlanConfigurer {
Plan.Error.from(parent, ErrorMessage.InvalidTupleAccesor(index, config.span), None)
)

case parent @ BetweenTupleFunction(source, dest, plans) if config.side.isSource =>
case parent @ BetweenTupleFunction(source, dest, _) if config.side.isSource =>
Logger.debug(ds"Matched $parent")
parent.updateByIndexOrElse(index)(
recurse(_, tail, parent, config),
Expand All @@ -171,7 +170,7 @@ private[ducktape] object PlanConfigurer {
case parent: BetweenNonOptionOption[Erroneous, F] if config.side.isSource =>
parent.update(recurse(_, segments, parent, config))

case parent @ BetweenCoproducts(sourceTpe, destTpe, casePlans) =>
case parent @ BetweenCoproducts(_, _, casePlans) =>
def sideTpe(plan: Plan[Erroneous, Fallible]) =
if config.side.isSource then plan.source.tpe.repr else plan.dest.tpe.repr

Expand Down Expand Up @@ -253,7 +252,7 @@ private[ducktape] object PlanConfigurer {
plan match {
case suppressed: Plan.Error =>
Plan.Error.from(plan, ErrorMessage.InvalidPathSegment(segment, config.side, config.span), Some(suppressed))
case other =>
case _ =>
Plan.Error.from(plan, ErrorMessage.InvalidPathSegment(segment, config.side, config.span), None)
}

Expand Down Expand Up @@ -331,7 +330,7 @@ private[ducktape] object PlanConfigurer {
case plan: BetweenFallibleNonFallible[Erroneous] =>
plan.update(regional(_, modifier, plan))

case plan @ BetweenFallibles(_, _, _, elemPlan) =>
case plan @ BetweenFallibles(_, _, _, _) =>
plan.update(regional(_, modifier, plan))

case plan: Error =>
Expand Down Expand Up @@ -470,7 +469,7 @@ private[ducktape] object PlanConfigurer {
): List[Plan.Configured[Fallible]] =
plan match {
case configured: Plan.Configured[Fallible] => configured :: accumulator
case other => accumulator
case _ => accumulator
}
}
}
Loading