You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defexplanation(m: Message)(usingContext):String= {
valsb=newStringBuilder(
s"""| |${Blue("Explanation").show}
|${Blue("===========").show}""".stripMargin
)
sb.append(EOL).append(m.explanation)
if (m.explanation.lastOption !=Some(EOL)) sb.append(EOL) // This is always true so it always adds EOL
sb.toString
}
m.explanation.lastOption and Some(EOL) can never be equal since m.explanation is String which means m.explanation.lastOption is Option[Char] not Option[String] whereas Some(EOL) is Option[String].
Therefore, m.explanation.lastOption != Some(EOL) is always true.
So whether the sb above has EOL at the end or not, it always adds EOL at the end which may result in duplicate EOL chars at the end of the String result from MessageRendering.explanation.
Besides, checking just the last Char might not be good enough. EOL is from java.lang.System.lineSeparator() so it might be just one Char like \n on xNix systems while it can be two Chars like \r\n on MS Windows systems.
Output
Expectation
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Summary
The result from
MessageRendering.explanation
may have duplicateEOL
Char
s at the end.Compiler version
3.0.0-RC3
fromprint scalaVersion
on sbt console.Minimized code
Sorry I don't have any use case for this but found some logic error in MessageRendering.explanation
m.explanation.lastOption
andSome(EOL)
can never be equal since m.explanation isString
which meansm.explanation.lastOption
isOption[Char]
notOption[String]
whereasSome(EOL)
isOption[String]
.Therefore,
m.explanation.lastOption != Some(EOL)
is alwaystrue
.So whether the
sb
above hasEOL
at the end or not, it always addsEOL
at the end which may result in duplicateEOL
chars at the end of theString
result fromMessageRendering.explanation
.Besides, checking just the last
Char
might not be good enough.EOL
is fromjava.lang.System.lineSeparator()
so it might be just oneChar
like\n
on xNix systems while it can be twoChar
s like\r\n
on MS Windows systems.Output
Expectation
The text was updated successfully, but these errors were encountered: