-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from jatcwang/scala3
Scala3
- Loading branch information
Showing
24 changed files
with
495 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ RUNNING_PID | |
metals.sbt | ||
.bsp | ||
TempGo.scala | ||
metals.sbt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Xmx3G |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
version=2.3.2 | ||
version="3.0.0-RC3" | ||
maxColumn = 120 | ||
trailingCommas = always | ||
continuationIndent.defnSite = 2 | ||
|
||
rewrite.rules = [PreferCurlyFors] | ||
rewrite.redundantBraces.stringInterpolation = true | ||
runner.dialect = scala3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
modules/core/src/main/scala-2.13/difflicious/utils/TypeNamePlatform.scala
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
modules/core/src/main/scala-3/difflicious/DifferGen.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package difflicious | ||
import difflicious.DiffResult.MismatchTypeResult | ||
import difflicious.differ.RecordDiffer | ||
import difflicious.utils.TypeName | ||
import difflicious.utils.TypeName.SomeTypeName | ||
import difflicious.DiffResult | ||
import difflicious.internal.EitherGetSyntax._ | ||
|
||
import scala.collection.immutable.ListMap | ||
import magnolia1._ | ||
|
||
import scala.collection.mutable | ||
|
||
trait DifferGen extends Derivation[Differ]: | ||
override def join[T](ctx: CaseClass[Differ, T]): Differ[T] = | ||
new RecordDiffer[T]( | ||
ctx.params.map { p => | ||
val getter = p.deref | ||
p.label -> Tuple2(getter.asInstanceOf[(T => Any)], p.typeclass.asInstanceOf[Differ[Any]]) | ||
}.to(ListMap), | ||
isIgnored = false, | ||
typeName = toDiffliciousTypeName(ctx.typeInfo) | ||
) | ||
|
||
override def split[T](ctx: SealedTrait[Differ, T]): Differ[T] = | ||
new SealedTraitDiffer(ctx, isIgnored = false) | ||
|
||
final class SealedTraitDiffer[T](ctx: SealedTrait[Differ, T], isIgnored: Boolean) extends Differ[T]: | ||
override type R = DiffResult | ||
|
||
override def diff(inputs: DiffInput[T]): DiffResult = inputs match | ||
case DiffInput.ObtainedOnly(obtained) => | ||
ctx.choose(obtained)(sub => sub.typeclass.diff(DiffInput.ObtainedOnly(sub.cast(obtained)))) | ||
case DiffInput.ExpectedOnly(expected) => | ||
ctx.choose(expected)(sub => sub.typeclass.diff(DiffInput.ExpectedOnly(sub.cast(expected)))) | ||
case DiffInput.Both(obtained, expected) => | ||
ctx.choose(obtained) { obtainedSubtype => | ||
ctx.choose(expected) { expectedSubtype => | ||
if obtainedSubtype.typeInfo.short == expectedSubtype.typeInfo.short then | ||
obtainedSubtype.typeclass.asInstanceOf[Differ[T]].diff(obtainedSubtype.value, expectedSubtype.value) | ||
else MismatchTypeResult( | ||
obtained = obtainedSubtype.typeclass.diff(DiffInput.ObtainedOnly(obtainedSubtype.cast(obtained))), | ||
obtainedTypeName = toDiffliciousTypeName(obtainedSubtype.typeInfo), | ||
expected = expectedSubtype.typeclass.diff(DiffInput.ExpectedOnly(expectedSubtype.cast(expected))), | ||
expectedTypeName = toDiffliciousTypeName(expectedSubtype.typeInfo), | ||
pairType = PairType.Both, | ||
isIgnored = isIgnored, | ||
) | ||
} | ||
} | ||
|
||
|
||
override def configureIgnored(newIgnored: Boolean): Differ[T] = | ||
val newSubtypes = mutable.ArrayBuffer.empty[SealedTrait.Subtype[Differ, T, Any]] | ||
ctx.subtypes.map { sub => | ||
newSubtypes += SealedTrait.Subtype[Differ, T, Any]( | ||
typeInfo = sub.typeInfo, | ||
annotations = sub.annotations, | ||
typeAnnotations = sub.typeAnnotations, | ||
isObject = sub.isObject, | ||
index = sub.index, | ||
callByNeed = | ||
CallByNeed(sub.typeclass.configureRaw(ConfigurePath.current, ConfigureOp.SetIgnored(newIgnored)).unsafeGet.asInstanceOf[Differ[Any]]), | ||
isType = sub.cast.isDefinedAt, | ||
asType = sub.cast.apply, | ||
) | ||
} | ||
val newSealedTrait = new SealedTrait( | ||
typeInfo = ctx.typeInfo, | ||
subtypes = IArray(newSubtypes.toArray: _*), | ||
annotations = ctx.annotations, | ||
typeAnnotations = ctx.typeAnnotations, | ||
) | ||
new SealedTraitDiffer[T](newSealedTrait, isIgnored = newIgnored) | ||
|
||
protected def configurePath( | ||
step: String, | ||
nextPath: ConfigurePath, | ||
op: ConfigureOp | ||
): Either[ConfigureError, Differ[T]] = | ||
ctx.subtypes.zipWithIndex.find{ (sub, _) => sub.typeInfo.short == step} match { | ||
case Some((sub, idx)) => | ||
sub.typeclass | ||
.configureRaw(nextPath, op) | ||
.map { newDiffer => | ||
val newSubtype = SealedTrait.Subtype[Differ, T, Any]( | ||
typeInfo = sub.typeInfo, | ||
annotations = sub.annotations, | ||
typeAnnotations = sub.typeAnnotations, | ||
isObject = sub.isObject, | ||
index = sub.index, | ||
callByNeed = CallByNeed(newDiffer.asInstanceOf[Differ[Any]]), | ||
isType = sub.cast.isDefinedAt, | ||
asType = sub.cast.apply, | ||
) | ||
val newSubtypes = ctx.subtypes.updated(idx, newSubtype) | ||
val newSealedTrait = new SealedTrait( | ||
typeInfo = ctx.typeInfo, | ||
subtypes = newSubtypes, | ||
annotations = ctx.annotations, | ||
typeAnnotations = ctx.typeAnnotations, | ||
) | ||
new SealedTraitDiffer[T](newSealedTrait, isIgnored) | ||
} | ||
case None => | ||
Left(ConfigureError.UnrecognizedSubType(nextPath, ctx.subtypes.map(_.typeInfo.short).toVector)) | ||
} | ||
|
||
protected def configurePairBy(path: ConfigurePath, op: ConfigureOp.PairBy[_]): Either[ConfigureError, Differ[T]] = | ||
Left(ConfigureError.InvalidConfigureOp(path, op, "SealedTraitDiffer")) | ||
|
||
end SealedTraitDiffer | ||
|
||
private def toDiffliciousTypeName(typeInfo: TypeInfo): SomeTypeName = { | ||
TypeName( | ||
long = s"${typeInfo.owner}.${typeInfo.short}", | ||
short = typeInfo.short, | ||
typeArguments = typeInfo.typeParams.map(toDiffliciousTypeName).toList | ||
) | ||
} |
Oops, something went wrong.