Skip to content

Commit e0728b3

Browse files
committed
Extract throwing the assertions of assert() in the runtime library.
1 parent b2c28ef commit e0728b3

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
5454
val sources = List(
5555
mkSource("assert(true)", "()"),
5656
mkSource("assert(true, ???)", "()"),
57-
mkSource("assert(false)", "{ throw new java.lang.AssertionError(\"assertion failed\") }")
57+
mkSource("assert(false)", "scala.runtime.Scala3RunTime.assertFailed()")
5858
)
5959
for (source <- sources)
6060
checkBCode(source) { dir =>

library/src/dotty/DottyPredef.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ object DottyPredef {
55

66
inline final def assert(inline assertion: Boolean, inline message: => Any): Unit = {
77
if (!assertion)
8-
throw new java.lang.AssertionError("assertion failed: " + message)
8+
scala.runtime.Scala3RunTime.assertFailed(message)
99
}
1010

1111
transparent inline final def assert(inline assertion: Boolean): Unit = {
1212
if (!assertion)
13-
throw new java.lang.AssertionError("assertion failed")
13+
scala.runtime.Scala3RunTime.assertFailed()
1414
}
1515

1616
inline final def implicitly[T](implicit ev: T): T = ev
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package scala.runtime
2+
3+
object Scala3RunTime:
4+
5+
// Called by inline def assert's. Extracted to minimize the bytecode size at call site.
6+
7+
def assertFailed(message: Any): Nothing =
8+
throw new java.lang.AssertionError("assertion failed: " + message)
9+
10+
def assertFailed(): Nothing =
11+
throw new java.lang.AssertionError("assertion failed")
12+
13+
end Scala3RunTime

0 commit comments

Comments
 (0)