Skip to content

Commit 2db4447

Browse files
committed
indicate that truncation happened
1 parent 2da662a commit 2db4447

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
7575
}
7676
}
7777

78-
stringOfMaybeTruncated
78+
(value: Object, maxElements: Int) => {
79+
// `ScalaRuntime.stringOf` may truncate the output, in which case we want to indicate that fact to the user
80+
// In order to figure out if it did get truncated, we invoke it twice - once with the `maxElements` that we
81+
// want to print, and once without a limit. If the first is shorter, truncation did occur.
82+
val maybeTruncated = stringOfMaybeTruncated(value, maxElements)
83+
val notTruncated = stringOfMaybeTruncated(value, Int.MaxValue)
84+
if (maybeTruncated.length == notTruncated.length) maybeTruncated
85+
else maybeTruncated + infoOutputGotTruncated
86+
}
87+
7988
}
8089
myClassLoader
8190
}

compiler/test-resources/repl/settings-repl-max-print-elements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ val res0: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
44
scala>:settings -Vrepl-max-print-elements:20
55

66
scala> 1.to(300).toList
7-
val res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
7+
val res1: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) ... large output truncated, print value to show all

0 commit comments

Comments
 (0)