Skip to content

Commit

Permalink
Merge pull request #550 from tgodzik/fix-null
Browse files Browse the repository at this point in the history
Don't call toString on null values
  • Loading branch information
tgodzik authored Aug 23, 2021
2 parents 8b7f6dc + 7bb1495 commit dd79fac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions runtime/src/main/scala-3/mdoc/internal/document/Printing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package mdoc.internal.document
import Compat.TPrint

object Printing {
inline def stringValue[T](value: T) = value.toString
inline def stringValue[T](value: T) = nullableToString(value)
inline def typeString[T](tprint: TPrint[T]) = tprint.render

inline def print[T](value: T, out : StringBuilder, width: Int, height: Int) = {
out.append(value.toString)
out.append(nullableToString(value))
}

inline def printOneLine[T](value: T, out : StringBuilder, width: Int) = {
out.append(value.toString.replace("\n",""))
out.append(nullableToString(value).replace("\n",""))
}

inline private def nullableToString[T](value: T) = {
if (value != null) value.toString else "null"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class WorksheetSuite extends BaseSuite {
|""".stripMargin
)

checkDecorations(
"null",
"""
|val x: String = null
|""".stripMargin,
"""|<val x: String = null> // : String = null
|x: String = null
|""".stripMargin
)

checkDecorations(
"import-future".tag(OnlyScala3),
"""|import $scalac.`-source future`
Expand Down

0 comments on commit dd79fac

Please sign in to comment.