Skip to content

Commit 8bbf6f4

Browse files
committed
update Scala version to 2.13.18 and enhance default argument handling
1 parent 11e6d7e commit 8bbf6f4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: [ubuntu-latest]
26-
scala: [2.13.17]
26+
scala: [2.13.18]
2727
java: [temurin@17, temurin@21]
2828
runs-on: ${{ matrix.os }}
2929
steps:

macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,18 @@ trait MacroCommons extends CompatMacroCommons { bundle =>
234234
primaryConstructorOf(clsTpe).typeSignatureIn(clsTpe)
235235
}
236236

237+
private def isDefaultAnnotArg(tree: Tree): Boolean = {
238+
(tree.tpe match {
239+
case AnnotatedType(annots, _) => annots.exists(_.tree.tpe.typeSymbol.name.toString == "defaultArg")
240+
case _ => false
241+
}) ||
242+
tree.symbol != null && tree.symbol.isSynthetic && tree.symbol.name.decodedName.toString.contains("$default$")
243+
}
244+
237245
lazy val treeRes: Res[Tree] = annotTree match {
238246
case Apply(constr, args) =>
239247
val newArgs = (args zip constructorSig.paramLists.head) map {
240-
case (arg, param) if param.asTerm.isParamWithDefault && arg.symbol != null &&
241-
arg.symbol.isSynthetic && arg.symbol.name.decodedName.toString.contains("$default$") =>
248+
case (arg, param) if param.asTerm.isParamWithDefault && isDefaultAnnotArg(arg) =>
242249
if (findAnnotation(param, DefaultsToNameAT).nonEmpty)
243250
Ok(q"${subject.name.decodedName.toString}")
244251
else
@@ -283,7 +290,7 @@ trait MacroCommons extends CompatMacroCommons { bundle =>
283290
.collectFirst {
284291
case (param, arg) if param.name == subSym.name => arg match {
285292
case Literal(Constant(value: T)) => value
286-
case Literal(Constant(null)) => whenDefault
293+
case _ if param.asTerm.isParamWithDefault && isDefaultAnnotArg(arg) => whenDefault
287294
case t if param.asTerm.isParamWithDefault && t.symbol.isSynthetic &&
288295
t.symbol.name.decodedName.toString.contains("$default$") => whenDefault
289296
case t if classTag[T] == classTag[Tree] => t.asInstanceOf[T]
@@ -824,6 +831,7 @@ trait MacroCommons extends CompatMacroCommons { bundle =>
824831
case class LitOrDefault[T: ClassTag](default: T) {
825832
def unapply(tree: Tree): Option[T] = tree match {
826833
case Literal(Constant(value: T)) => Some(value)
834+
case _ if tree.tpe != null && tree.tpe.toString.endsWith("@scala.annotation.meta.defaultArg") => Some(default)
827835
case Select(_, TermName(n)) if n.startsWith("$lessinit$greater$default$") => Some(default)
828836
case _ => None
829837
}

project/Commons.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Commons extends ProjectGroup("commons") {
6565
Developer("ddworak", "Dawid Dworak", "[email protected]", url("https://github.com/ddworak")),
6666
),
6767

68-
scalaVersion := "2.13.17",
68+
scalaVersion := "2.13.18",
6969
compileOrder := CompileOrder.Mixed,
7070

7171
githubWorkflowTargetTags ++= Seq("v*"),

0 commit comments

Comments
 (0)