Skip to content

Commit 8e4118b

Browse files
committed
chore: add Predef.assert from stdlib patches
1 parent 4e75aa2 commit 8e4118b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

library/src/scala/Predef.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import scala.language.`2.13`
1616
import scala.language.implicitConversions
1717

1818
import scala.collection.{mutable, immutable, ArrayOps, StringOps}, immutable.WrappedString
19-
import scala.annotation.{elidable, experimental, implicitNotFound}, elidable.ASSERTION
19+
import scala.annotation.{elidable, experimental, implicitNotFound, publicInBinary, targetName }, elidable.ASSERTION
2020
import scala.annotation.meta.{ companionClass, companionMethod }
2121
import scala.annotation.internal.{ RuntimeChecked }
2222
import scala.compiletime.summonFrom
@@ -285,8 +285,8 @@ object Predef extends LowPriorityImplicits {
285285
* @param assertion the expression to test
286286
* @group assertions
287287
*/
288-
@elidable(ASSERTION)
289-
def assert(assertion: Boolean): Unit = {
288+
@elidable(ASSERTION) @publicInBinary
289+
@targetName("assert") private[scala] def scala2Assert(assertion: Boolean): Unit = {
290290
if (!assertion)
291291
throw new java.lang.AssertionError("assertion failed")
292292
}
@@ -300,12 +300,18 @@ object Predef extends LowPriorityImplicits {
300300
* @param message a String to include in the failure message
301301
* @group assertions
302302
*/
303-
@elidable(ASSERTION) @inline
304-
final def assert(assertion: Boolean, message: => Any): Unit = {
303+
@elidable(ASSERTION) @inline @publicInBinary
304+
@targetName("assert") private[scala] final def scala2Assert(assertion: Boolean, message: => Any): Unit = {
305305
if (!assertion)
306306
throw new java.lang.AssertionError("assertion failed: "+ message)
307307
}
308308

309+
transparent inline def assert(inline assertion: Boolean, inline message: => Any): Unit =
310+
if !assertion then scala.runtime.Scala3RunTime.assertFailed(message)
311+
312+
transparent inline def assert(inline assertion: Boolean): Unit =
313+
if !assertion then scala.runtime.Scala3RunTime.assertFailed()
314+
309315
/** Tests an expression, throwing an `AssertionError` if false.
310316
* This method differs from assert only in the intent expressed:
311317
* assert contains a predicate which needs to be proven, while

0 commit comments

Comments
 (0)