Skip to content

Commit 8868c12

Browse files
committed
Restore support of -Yexplicit-nulls compiler options for String and ::[?] values
1 parent 78663bc commit 8868c12

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

build.sbt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ lazy val `jsoniter-scala-next-tests` = crossProject(JVMPlatform, JSPlatform, Nat
241241
.settings(noPublishSettings)
242242
.settings(
243243
crossScalaVersions := Seq("3.7.3"),
244+
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
245+
case Some((2, _)) => Seq()
246+
case _ => Seq(
247+
"-Yexplicit-nulls"
248+
)
249+
}),
244250
libraryDependencies ++= Seq(
245251
"org.scalatestplus" %%% "scalacheck-1-18" % "3.2.19.0" % Test,
246252
"org.scalatest" %%% "scalatest" % "3.2.19" % Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ private class JsonCodecMakerInstance(cfg: CodecMakerConfig)(using Quotes) {
18821882
val tpe = types.head
18831883
val implValueCodec = findImplicitValueCodec(tpe)
18841884
if (implValueCodec.isDefined) '{ ${implValueCodec.get}.nullValue }
1885-
else if (tpe =:= stringTpe) Literal(NullConstant()).asExpr
1885+
else if (tpe =:= stringTpe) '{ null.asInstanceOf[String] }
18861886
else if (tpe =:= booleanTpe) Literal(BooleanConstant(false)).asExpr
18871887
else if (tpe =:= byteTpe) Literal(ByteConstant(0)).asExpr
18881888
else if (tpe =:= shortTpe) Literal(ShortConstant(0)).asExpr
@@ -1913,7 +1913,7 @@ private class JsonCodecMakerInstance(cfg: CodecMakerConfig)(using Quotes) {
19131913
typeArg1(tpe).asType match { case '[t1] => '{ IArray.unsafeFromArray(${genNewArray[t1](Expr(0))}) } }
19141914
} else if (tpe <:< TypeRepr.of[mutable.BitSet]) '{ new mutable.BitSet }
19151915
else if (tpe <:< TypeRepr.of[collection.BitSet]) withNullValueFor(tpe)('{ immutable.BitSet.empty })
1916-
else if (tpe <:< TypeRepr.of[::[?]]) Literal(NullConstant()).asExpr
1916+
else if (tpe <:< TypeRepr.of[::[?]]) '{ null.asInstanceOf[T] }
19171917
else if (tpe <:< TypeRepr.of[List[?]] || tpe.typeSymbol == TypeRepr.of[Seq[?]].typeSymbol) '{ Nil }
19181918
else if (tpe <:< TypeRepr.of[collection.SortedSet[?]] || tpe <:< TypeRepr.of[mutable.PriorityQueue[?]]) {
19191919
val tpe1 = typeArg1(tpe)

0 commit comments

Comments
 (0)