Skip to content

Commit a4ac534

Browse files
committed
Define Predef.assert overwrite directly in Scala 2 library TASTy
Define `assert` in `scala.Predef` instead `scala.runtime.stdLibPatches.Predef`. We assume that all patches to `scala.Predef` are inline methods, therefore if we see an inline method in `scala.Predef` we do not patch it with the method in `scala.runtime.stdLibPatches.Predef`.
1 parent 4de067c commit a4ac534

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ class Definitions {
14371437
!patch.isConstructor && !patch.isOneOf(PrivateOrSynthetic))
14381438
for patch <- patches if !recurse(patch) do
14391439
val e = scope.lookupEntry(patch.name)
1440-
if e != null then scope.unlink(e)
1440+
if e != null && !e.sym.isInlineMethod then scope.unlink(e)
14411441
for patch <- patches do
14421442
patch.ensureCompleted()
14431443
if !recurse(patch) then

project/MiMaFilters.scala

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ object MiMaFilters {
2020
val StdlibBootstrappedBackwards: Map[String, Seq[ProblemFilter]] = Map(
2121
Build.stdlibBootstrappedVersion -> {
2222
Seq(
23+
// Methods overwritten in `scala.Predef` instead of `scala.runtime.stdLibPatches`
24+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Predef.assert"),
25+
2326
// Files that are not compiled in the bootstrapped library
2427
ProblemFilters.exclude[MissingClassProblem]("scala.AnyVal"),
2528

scala2-library-bootstrapped/src/scala/Predef.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ object Predef extends LowPriorityImplicits {
274274
* @group assertions
275275
*/
276276
@elidable(ASSERTION) @inline
277-
final def assert(assertion: Boolean, message: => Any): Unit = {
278-
if (!assertion)
279-
throw new java.lang.AssertionError("assertion failed: "+ message)
277+
transparent inline def assert(inline assertion: Boolean, inline message: => Any): Unit = {
278+
if !assertion then
279+
scala.runtime.Scala3RunTime.assertFailed(message)
280280
}
281281

282282
/** Tests an expression, throwing an `AssertionError` if false.

0 commit comments

Comments
 (0)