Skip to content

Commit 65a70f8

Browse files
authored
Merge pull request scala/scala#10226 from som-snytt/tweak/this-avoids-discard
Leverage this.type
2 parents 2cae248 + 5ffc4a5 commit 65a70f8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

library/src/scala/MatchError.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ final class MatchError(@transient obj: Any) extends RuntimeException {
2323
private[this] lazy val objString = {
2424
def ofClass = "of class " + obj.getClass.getName
2525
if (obj == null) "null"
26-
else try {
27-
obj.toString() + " (" + ofClass + ")"
28-
} catch {
29-
case _: Throwable => "an instance " + ofClass
30-
}
26+
else
27+
try s"$obj ($ofClass)"
28+
catch {
29+
case _: Throwable => "an instance " + ofClass
30+
}
3131
}
3232

3333
@throws[java.io.ObjectStreamException]

library/src/scala/collection/mutable/ArrayBuffer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ object ArrayBuffer extends StrictOptimizedSeqFactory[ArrayBuffer] {
296296
if (k >= 0) {
297297
// Avoid reallocation of buffer if length is known
298298
val array = ensureSize(emptyArray, 0, k) // don't duplicate sizing logic, and check VM array size limit
299-
IterableOnce.copyElemsToArray(coll, array.asInstanceOf[Array[Any]])
299+
val actual = IterableOnce.copyElemsToArray(coll, array.asInstanceOf[Array[Any]])
300+
if (actual != k) throw new IllegalStateException(s"Copied $actual of $k")
300301
new ArrayBuffer[B](array, k)
301302
}
302303
else new ArrayBuffer[B] ++= coll

0 commit comments

Comments
 (0)