Skip to content

Commit 541280f

Browse files
committed
add adjust to not cut a Unicode character in half
1 parent 8111676 commit 541280f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,23 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
6464
myClassLoader
6565
}
6666

67-
/** Used to elide output in replStringOf.
67+
/** Used to elide long output in replStringOf.
68+
*
6869
* TODO: Perhaps implement setting scala.repl.maxprintstring as in Scala 2, but
6970
* then this bug will surface, so perhaps better not?
7071
* https://github.com/scala/bug/issues/12337
7172
*/
7273
private[repl] def truncate(str: String): String =
73-
if str.length > MaxStringElements then str.take(MaxStringElements - 3) + "..."
74+
def adjust(s: String): String = // to not cut a Unicode character in half
75+
if s.nonEmpty && s.last.isUnicodeIdentifierStart then s.dropRight(1)
76+
else s
77+
78+
if str.length > MaxStringElements then adjust(str.take(MaxStringElements - 3)) + "..."
7479
else str
80+
end truncate
7581

7682
/** Return a String representation of a value we got from `classLoader()`. */
7783
private[repl] def replStringOf(value: Object)(using Context): String = {
78-
7984
assert(myReplStringOf != null,
8085
"replStringOf should only be called on values creating using `classLoader()`, but `classLoader()` has not been called so far")
8186
truncate(myReplStringOf(value))

0 commit comments

Comments
 (0)