Skip to content

Commit b94f1f5

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 472ae72 commit b94f1f5

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ object Predef extends LowPriorityImplicits {
259259
* @group assertions
260260
*/
261261
@elidable(ASSERTION)
262-
def assert(assertion: Boolean): Unit = {
262+
transparent inline def assert(inline assertion: Boolean): Unit = {
263263
if (!assertion)
264264
throw new java.lang.AssertionError("assertion failed")
265265
}
@@ -274,7 +274,7 @@ object Predef extends LowPriorityImplicits {
274274
* @group assertions
275275
*/
276276
@elidable(ASSERTION) @inline
277-
final def assert(assertion: Boolean, message: => Any): Unit = {
277+
transparent inline def assert(inline assertion: Boolean, inline message: => Any): Unit = {
278278
if (!assertion)
279279
throw new java.lang.AssertionError("assertion failed: "+ message)
280280
}

0 commit comments

Comments
 (0)