Skip to content

Commit 530612b

Browse files
committed
Clean up Scala 3 compiler warnings
1 parent 98c4d32 commit 530612b

File tree

2 files changed

+84
-43
lines changed

2 files changed

+84
-43
lines changed

build.sbt

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@ lazy val commonSettings = Seq(
2727
"-unchecked",
2828
"-Xmacro-settings:" + sys.props.getOrElse("macro.settings", "none")
2929
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
30-
case Some((2, 12)) => Seq("-language:higherKinds", "-opt:l:method")
31-
case Some((2, 13)) => Seq("-opt:l:method")
32-
case _ => Seq("-Xcheck-macros", "-explain")
30+
case Some((2, 12)) => Seq(
31+
"-language:higherKinds",
32+
"-opt:l:method")
33+
case Some((2, 13)) => Seq(
34+
"-opt:l:method"
35+
)
36+
case _ => Seq(
37+
"-Xcheck-macros",
38+
"-explain",
39+
"-Wconf:msg=Ignoring [this] qualifier.:s",
40+
"-Wconf:msg=Implicit parameters should be provided with a `using` clause:s",
41+
)
3342
}),
3443
compileOrder := CompileOrder.JavaThenScala,
3544
Test / testOptions += Tests.Argument("-oDF"),
@@ -156,6 +165,12 @@ lazy val `jsoniter-scala-core` = crossProject(JVMPlatform, JSPlatform, NativePla
156165
.settings(publishSettings)
157166
.settings(
158167
crossScalaVersions := Seq("3.3.6", "2.13.16", "2.12.20"),
168+
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
169+
case Some((2, _)) => Seq()
170+
case _ => Seq(
171+
"-source:3.3"
172+
)
173+
}),
159174
libraryDependencies ++= Seq(
160175
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.13.0" % Test,
161176
"org.scalatestplus" %%% "scalacheck-1-18" % "3.2.19.0" % Test,
@@ -188,6 +203,12 @@ lazy val `jsoniter-scala-macros` = crossProject(JVMPlatform, JSPlatform, NativeP
188203
.settings(publishSettings)
189204
.settings(
190205
crossScalaVersions := Seq("3.3.6", "2.13.16", "2.12.20"),
206+
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
207+
case Some((2, _)) => Seq()
208+
case _ => Seq(
209+
"-source:3.3"
210+
)
211+
}),
191212
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
192213
case Some((2, _)) => Seq(
193214
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
@@ -237,6 +258,12 @@ lazy val `jsoniter-scala-circe` = crossProject(JVMPlatform, JSPlatform, NativePl
237258
.settings(publishSettings)
238259
.settings(
239260
crossScalaVersions := Seq("3.3.6", "2.13.16", "2.12.20"),
261+
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
262+
case Some((2, _)) => Seq()
263+
case _ => Seq(
264+
"-source:3.3"
265+
)
266+
}),
240267
libraryDependencies ++= Seq(
241268
"io.circe" %%% "circe-core" % "0.14.14",
242269
"io.circe" %%% "circe-parser" % "0.14.14" % Test,
@@ -261,8 +288,16 @@ lazy val `jsoniter-scala-benchmark` = crossProject(JVMPlatform, JSPlatform)
261288
.settings(
262289
crossScalaVersions := Seq("3.7.3", "2.13.16"),
263290
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
264-
case Some((2, _)) => Seq("-Wopt", "-opt:l:inline", "-opt-inline-from:**:!java.**")
265-
case _ => Seq("-source:3.3", "-Xmax-inlines:100", "-preview")
291+
case Some((2, _)) => Seq(
292+
"-Wopt",
293+
"-opt:l:inline",
294+
"-opt-inline-from:**:!java.**"
295+
)
296+
case _ => Seq(
297+
"-source:3.3",
298+
"-Xmax-inlines:100",
299+
"-preview"
300+
)
266301
}),
267302
libraryDependencies ++= Seq(
268303
"com.disneystreaming.smithy4s" %%% "smithy4s-json" % "0.18.42",

jsoniter-scala-macros/shared/src/main/scala-3/com/github/plokhotnyuk/jsoniter_scala/macros/JsonCodecMaker.scala

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,14 @@ object JsonCodecMaker {
870870
def scalaCollectionBuilder(tpe: TypeRepr, eTpe: TypeRepr): Term =
871871
TypeApply(Select.unique(scalaCollectionCompanion(tpe), "newBuilder"), List(Inferred(eTpe)))
872872

873-
def scalaCollectionEmptyNoArgs(cTpe: TypeRepr, eTpe: TypeRepr): Term =
874-
TypeApply(Select.unique(scalaCollectionCompanion(cTpe), "empty"), List(Inferred(eTpe)))
873+
def scalaMapBuilder(tpe: TypeRepr, kTpe: TypeRepr, vTpe: TypeRepr): Term =
874+
TypeApply(Select.unique(scalaCollectionCompanion(tpe), "newBuilder"), List(Inferred(kTpe), Inferred(vTpe)))
875875

876-
def scalaMapEmptyNoArgs(cTpe: TypeRepr, kTpe: TypeRepr, vTpe: TypeRepr): Term =
877-
TypeApply(Select.unique(scalaCollectionCompanion(cTpe), "empty"), List(Inferred(kTpe), Inferred(vTpe)))
876+
def scalaCollectionEmpty(tpe: TypeRepr, eTpe: TypeRepr): Term =
877+
TypeApply(Select.unique(scalaCollectionCompanion(tpe), "empty"), List(Inferred(eTpe)))
878+
879+
def scalaMapEmpty(tpe: TypeRepr, kTpe: TypeRepr, vTpe: TypeRepr): Term =
880+
TypeApply(Select.unique(scalaCollectionCompanion(tpe), "empty"), List(Inferred(kTpe), Inferred(vTpe)))
878881

879882
def scala2EnumerationObject(tpe: TypeRepr): Expr[Enumeration] = tpe match
880883
case TypeRef(eTpe, _) => Ref(eTpe.termSymbol).asExpr.asInstanceOf[Expr[Enumeration]]
@@ -1126,7 +1129,7 @@ object JsonCodecMaker {
11261129
if (tpeTypeArgs ne Nil) fieldTpe = fieldTpe.substituteTypes(typeParams, tpeTypeArgs)
11271130
fieldTpe match
11281131
case TypeLambda(_, _, _) =>
1129-
fail(s"Hight-kinded types are not supported for type '${tpe.show}' with field type for $name '${fieldTpe.show}'")
1132+
fail(s"Type lambdas are not supported for type '${tpe.show}' with field type for $name '${fieldTpe.show}'")
11301133
case TypeBounds(_, _) =>
11311134
fail(s"Type bounds are not supported for type '${tpe.show}' with field type for $name '${fieldTpe.show}'")
11321135
case _ =>
@@ -1135,11 +1138,11 @@ object JsonCodecMaker {
11351138
val dvMembers = companionClass.methodMember("$lessinit$greater$default$" + i)
11361139
if (dvMembers.isEmpty) fail(s"Can't find default value for $name in class ${tpe.show}")
11371140
val methodSymbol = dvMembers.head
1138-
val dvSelectNoTArgs = companionModuleRef.select(methodSymbol)
1141+
val dvSelectNoTypes = companionModuleRef.select(methodSymbol)
11391142
val dvSelect = methodSymbol.paramSymss match
1140-
case Nil => dvSelectNoTArgs
1143+
case Nil => dvSelectNoTypes
11411144
case List(params) if params.exists(_.isTypeParam) =>
1142-
TypeApply(dvSelectNoTArgs, tpeTypeArgs.map(Inferred(_)))
1145+
TypeApply(dvSelectNoTypes, tpeTypeArgs.map(Inferred(_)))
11431146
case paramss => fail(s"Default method for $name of class ${tpe.show} have a complex parameter list: $paramss")
11441147
new Some(dvSelect)
11451148
} else None
@@ -1874,27 +1877,28 @@ object JsonCodecMaker {
18741877
else if (tpe <:< TypeRepr.of[List[?]] || tpe.typeSymbol == TypeRepr.of[Seq[?]].typeSymbol) '{ Nil }
18751878
else if (tpe <:< TypeRepr.of[collection.SortedSet[?]] || tpe <:< TypeRepr.of[mutable.PriorityQueue[?]]) {
18761879
val tpe1 = typeArg1(tpe)
1877-
Apply(scalaCollectionEmptyNoArgs(tpe, tpe1), List(summonOrdering(tpe1))).asExpr
1880+
Apply(scalaCollectionEmpty(tpe, tpe1), List(summonOrdering(tpe1))).asExpr
18781881
} else if (tpe <:< TypeRepr.of[mutable.ArraySeq[?]] || tpe <:< TypeRepr.of[immutable.ArraySeq[?]] ||
18791882
tpe <:< TypeRepr.of[mutable.UnrolledBuffer[?]]) {
18801883
val tpe1 = typeArg1(tpe)
1881-
Apply(scalaCollectionEmptyNoArgs(tpe, tpe1), List(summonClassTag(tpe1))).asExpr
1884+
Apply(scalaCollectionEmpty(tpe, tpe1), List(summonClassTag(tpe1))).asExpr
18821885
} else if (tpe <:< TypeRepr.of[immutable.IntMap[?]] || tpe <:< TypeRepr.of[immutable.LongMap[?]] ||
18831886
tpe <:< TypeRepr.of[immutable.Seq[?]] || tpe <:< TypeRepr.of[immutable.Set[?]]) withNullValueFor(tpe) {
1884-
scalaCollectionEmptyNoArgs(tpe, typeArg1(tpe)).asExpr
1885-
} else if (tpe <:< TypeRepr.of[mutable.LongMap[?]]) scalaCollectionEmptyNoArgs(tpe, typeArg1(tpe)).asExpr
1887+
scalaCollectionEmpty(tpe, typeArg1(tpe)).asExpr
1888+
} else if (tpe <:< TypeRepr.of[mutable.LongMap[?]]) scalaCollectionEmpty(tpe, typeArg1(tpe)).asExpr
18861889
else if (tpe <:< TypeRepr.of[collection.SortedMap[?, ?]] || tpe <:< TypeRepr.of[mutable.CollisionProofHashMap[?, ?]]) {
18871890
val tpe1 = typeArg1(tpe)
1888-
Apply(scalaMapEmptyNoArgs(tpe, tpe1, typeArg2(tpe)), List(summonOrdering(tpe1))).asExpr
1891+
Apply(scalaMapEmpty(tpe, tpe1, typeArg2(tpe)), List(summonOrdering(tpe1))).asExpr
18891892
} else if (tpe <:< TypeRepr.of[immutable.TreeSeqMap[?, ?]]) withNullValueFor(tpe) {
1890-
(typeArg1(tpe).asType, typeArg2(tpe).asType) match
1891-
case ('[t1], '[t2]) => '{ immutable.TreeSeqMap.empty[t1, t2] }
1893+
typeArg1(tpe).asType match { case '[t1] =>
1894+
typeArg2(tpe).asType match { case '[t2] => '{ immutable.TreeSeqMap.empty[t1, t2] } }
1895+
}
18921896
} else if (tpe <:< TypeRepr.of[immutable.Map[?, ?]]) withNullValueFor(tpe) {
1893-
scalaMapEmptyNoArgs(tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1897+
scalaMapEmpty(tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
18941898
} else if (tpe <:< TypeRepr.of[collection.Map[?, ?]]) {
1895-
scalaMapEmptyNoArgs(tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
1899+
scalaMapEmpty(tpe, typeArg1(tpe), typeArg2(tpe)).asExpr
18961900
} else if (tpe <:< TypeRepr.of[Iterable[?]] || tpe <:< TypeRepr.of[Iterator[?]]) {
1897-
scalaCollectionEmptyNoArgs(tpe, typeArg1(tpe)).asExpr
1901+
scalaCollectionEmpty(tpe, typeArg1(tpe)).asExpr
18981902
} else if (tpe <:< TypeRepr.of[Array[?]]) withNullValueFor(tpe) {
18991903
typeArg1(tpe).asType match { case '[t1] => genNewArray[t1](Expr(0)) }
19001904
} else if (isIArray(tpe)) withNullValueFor(tpe) {
@@ -2417,7 +2421,7 @@ object JsonCodecMaker {
24172421
val tpe1 = typeArg1(tpe)
24182422
tpe1.asType match
24192423
case '[t1] =>
2420-
val newBuilder = withNullValueFor(tpe)(scalaCollectionEmptyNoArgs(tpe, tpe1).asExpr.asInstanceOf[Expr[immutable.IntMap[t1]]])
2424+
val newBuilder = withNullValueFor(tpe)(scalaCollectionEmpty(tpe, tpe1).asExpr.asInstanceOf[Expr[immutable.IntMap[t1]]])
24212425
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false, in)
24222426
(if (cfg.mapAsArray) {
24232427
val readKey =
@@ -2438,7 +2442,7 @@ object JsonCodecMaker {
24382442
val tDefault = default.asInstanceOf[Expr[mutable.LongMap[t1]]]
24392443
val newBuilder = '{
24402444
if ($tDefault.isEmpty) $tDefault
2441-
else ${scalaCollectionEmptyNoArgs(tpe, tpe1).asExpr.asInstanceOf[Expr[mutable.LongMap[t1]]]}
2445+
else ${scalaCollectionEmpty(tpe, tpe1).asExpr.asInstanceOf[Expr[mutable.LongMap[t1]]]}
24422446
}
24432447
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false, in)
24442448
(if (cfg.mapAsArray) {
@@ -2455,7 +2459,7 @@ object JsonCodecMaker {
24552459
val tpe1 = typeArg1(tpe)
24562460
tpe1.asType match
24572461
case '[t1] =>
2458-
val newBuilder = withNullValueFor(tpe)(scalaCollectionEmptyNoArgs(tpe, tpe1).asExpr.asInstanceOf[Expr[immutable.LongMap[t1]]])
2462+
val newBuilder = withNullValueFor(tpe)(scalaCollectionEmpty(tpe, tpe1).asExpr.asInstanceOf[Expr[immutable.LongMap[t1]]])
24592463
val readVal = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false, in)
24602464
(if (cfg.mapAsArray) {
24612465
val readKey =
@@ -2474,10 +2478,10 @@ object JsonCodecMaker {
24742478
tpe <:< TypeRepr.of[mutable.CollisionProofHashMap[?, ?]]) withDecoderFor(methodKey, default, in) { (in, default) =>
24752479
val tpe1 = typeArg1(tpe)
24762480
val tpe2 = typeArg2(tpe)
2477-
(tpe1.asType, tpe2.asType) match
2478-
case ('[t1], '[t2]) =>
2481+
tpe1.asType match { case '[t1] =>
2482+
tpe2.asType match { case '[t2] =>
24792483
val tDefault = default.asInstanceOf[Expr[T & mutable.Map[t1, t2]]]
2480-
val emptyMapNoArgs = scalaMapEmptyNoArgs(tpe, tpe1, tpe2)
2484+
val emptyMapNoArgs = scalaMapEmpty(tpe, tpe1, tpe2)
24812485
val tEmpty =
24822486
(if (tpe <:< TypeRepr.of[mutable.SortedMap[?, ?]] || tpe <:< TypeRepr.of[mutable.CollisionProofHashMap[?, ?]]) {
24832487
Apply(emptyMapNoArgs, List(summonOrdering(tpe1)))
@@ -2494,20 +2498,18 @@ object JsonCodecMaker {
24942498
} else {
24952499
genReadMap(newBuilder, x => '{ $x.update(${genReadKey[t1](tpe1 :: types, in)}, $readVal2) }, identity, in, tDefault)
24962500
}).asInstanceOf[Expr[T]]
2501+
}
2502+
}
24972503
} else if (tpe <:< TypeRepr.of[collection.Map[?, ?]]) withDecoderFor(methodKey, default, in) { (in, default) =>
24982504
val tpe1 = typeArg1(tpe)
24992505
val tpe2 = typeArg2(tpe)
2500-
2501-
def builderNoApply =
2502-
TypeApply(Select.unique(scalaCollectionCompanion(tpe), "newBuilder"), List(Inferred(tpe1), Inferred(tpe2)))
2503-
2504-
(tpe1.asType, tpe2.asType) match
2505-
case ('[t1], '[t2]) =>
2506+
tpe1.asType match { case '[t1] =>
2507+
tpe2.asType match { case '[t2] =>
25062508
val readVal2 = genReadVal(tpe2 :: types, genNullValue[t2](tpe2 :: types), isStringified, false, in)
25072509
val newBuilder =
2508-
(if (tpe <:< TypeRepr.of[collection.SortedMap[?, ?]]) Apply(builderNoApply, List(summonOrdering(tpe1))).asExpr
2510+
(if (tpe <:< TypeRepr.of[collection.SortedMap[?, ?]]) Apply(scalaMapBuilder(tpe, tpe1, tpe2), List(summonOrdering(tpe1))).asExpr
25092511
else if (tpe <:< TypeRepr.of[immutable.TreeSeqMap[?, ?]]) '{ immutable.TreeSeqMap.newBuilder[t1, t2] }
2510-
else builderNoApply.asExpr).asInstanceOf[Expr[mutable.Builder[(t1, t2), T & collection.Map[t1, t2]]]]
2512+
else scalaMapBuilder(tpe, tpe1, tpe2).asExpr).asInstanceOf[Expr[mutable.Builder[(t1, t2), T & collection.Map[t1, t2]]]]
25112513
(if (cfg.mapAsArray) {
25122514
val readVal1 = genReadVal(tpe1 :: types, genNullValue[t1](tpe1 :: types), isStringified, false, in)
25132515
genReadMapAsArray(newBuilder,
@@ -2518,6 +2520,8 @@ object JsonCodecMaker {
25182520
genReadMap(newBuilder, x => '{ $x.addOne(new Tuple2($readKey, $readVal2)): Unit },
25192521
x => '{ $x.result() }, in, default)
25202522
}).asInstanceOf[Expr[T]]
2523+
}
2524+
}
25212525
} else if (tpe <:< TypeRepr.of[BitSet]) withDecoderFor(methodKey, default, in) { (in, default) =>
25222526
val readVal =
25232527
if (isStringified) '{ $in.readStringAsInt() }
@@ -2548,7 +2552,7 @@ object JsonCodecMaker {
25482552
tpe1.asType match
25492553
case '[t1] =>
25502554
val tDefault = default.asInstanceOf[Expr[T & mutable.Set[t1]]]
2551-
val emptySetNoOrdering = scalaCollectionEmptyNoArgs(tpe, tpe1)
2555+
val emptySetNoOrdering = scalaCollectionEmpty(tpe, tpe1)
25522556
val emptySet =
25532557
(if (tpe <:< TypeRepr.of[mutable.SortedSet[?]]) Apply(emptySetNoOrdering, List(summonOrdering(tpe1)))
25542558
else emptySetNoOrdering).asExpr.asInstanceOf[Expr[T & mutable.Set[t1]]]
@@ -2616,7 +2620,7 @@ object JsonCodecMaker {
26162620
val tpe1 = typeArg1(tpe)
26172621
tpe1.asType match
26182622
case '[t1] =>
2619-
val emptyCollectionNoArgs = scalaCollectionEmptyNoArgs(tpe, tpe1)
2623+
val emptyCollectionNoArgs = scalaCollectionEmpty(tpe, tpe1)
26202624
val emptyCollection =
26212625
(if (tpe <:< TypeRepr.of[mutable.UnrolledBuffer[?]]) {
26222626
Apply(emptyCollectionNoArgs, List(summonClassTag(tpe1)))
@@ -2783,7 +2787,7 @@ object JsonCodecMaker {
27832787
case namedTupleInfo: NamedTupleInfo =>
27842788
val i = fieldInfo.nonTransientFieldIndex
27852789
if (namedTupleInfo.isGeneric) {
2786-
TypeApply(Select(productElement.appliedTo(Literal(IntConstant(i))), asInstanceOfMethod), List(Inferred(fTpe)))
2790+
TypeApply(Select(Apply(productElement, List(Literal(IntConstant(i)))), asInstanceOfMethod), List(Inferred(fTpe)))
27872791
} else Select.unique(valRef, s"_${i + 1}")
27882792
case _ => Select(valRef, fieldInfo.getterOrField)
27892793
}.asExpr
@@ -3121,15 +3125,17 @@ object JsonCodecMaker {
31213125
tpe <:< TypeRepr.of[mutable.CollisionProofHashMap[?, ?]]) withEncoderFor(methodKey, m, out) { (out, x) =>
31223126
val tpe1 = typeArg1(tpe)
31233127
val tpe2 = typeArg2(tpe)
3124-
(tpe1.asType, tpe2.asType) match
3125-
case ('[t1], '[t2]) =>
3128+
tpe1.asType match { case '[t1] =>
3129+
tpe2.asType match { case '[t2] =>
31263130
def writeVal2(out: Expr[JsonWriter], v: Expr[t2])(using Quotes): Expr[Unit] =
31273131
genWriteVal(v, tpe2 :: types, isStringified, None, out)
31283132

31293133
val tx = x.asInstanceOf[Expr[collection.Map[t1, t2]]]
31303134
if (cfg.mapAsArray) {
31313135
genWriteMapAsArrayScala(tx, (out, k) => genWriteVal(k, tpe1 :: types, isStringified, None, out), writeVal2, out)
31323136
} else genWriteMapScala(tx, (out, k) => genWriteKey(k, tpe1 :: types, out), writeVal2, out)
3137+
}
3138+
}
31333139
} else if (tpe <:< TypeRepr.of[BitSet]) withEncoderFor(methodKey, m, out) { (out, x) =>
31343140
genWriteArray(x.asInstanceOf[Expr[BitSet]], (out, x1) => {
31353141
if (isStringified) '{ $out.writeValAsString($x1) }
@@ -3221,7 +3227,7 @@ object JsonCodecMaker {
32213227
case '[t] =>
32223228
val getter =
32233229
(if (isGeneric) {
3224-
TypeApply(Select(productElement.appliedTo(Literal(IntConstant(i - 1))), asInstanceOfMethod), List(Inferred(te)))
3230+
TypeApply(Select(Apply(productElement, List(Literal(IntConstant(i - 1)))), asInstanceOfMethod), List(Inferred(te)))
32253231
} else Select.unique(xTerm, "_" + i)).asExpr.asInstanceOf[Expr[t]]
32263232
genWriteVal(getter, te :: types, isStringified, None, out).asTerm
32273233
}

0 commit comments

Comments
 (0)