Skip to content

Commit 7e07214

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 206a78e commit 7e07214

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,11 +1437,14 @@ class Definitions {
14371437
)
14381438

14391439
if patchCls.exists then
1440+
val patchedInSource = mutable.Set.empty[Symbol] // example: symbol patched in scala2-library-bootstrapped/src/scala/Predef.scala
14401441
val patches = patchCls.info.decls.filter(patch =>
14411442
!patch.isConstructor && !patch.isOneOf(PrivateOrSynthetic))
14421443
for patch <- patches if !recurse(patch) do
14431444
val e = scope.lookupEntry(patch.name)
1444-
if e != null then scope.unlink(e)
1445+
if e != null then
1446+
if e.sym.isInlineMethod then patchedInSource += patch
1447+
else scope.unlink(e)
14451448
for patch <- patches do
14461449
patch.ensureCompleted()
14471450
if !recurse(patch) then
@@ -1452,8 +1455,9 @@ class Definitions {
14521455
case _ =>
14531456
makeNonClassSymbol(patch)
14541457
end match
1455-
sym.annotations = patch.annotations
1456-
scope.enter(sym)
1458+
if !patchedInSource(sym) then
1459+
sym.annotations = patch.annotations
1460+
scope.enter(sym)
14571461
if patch.isClass then
14581462
patch2(scope.lookup(patch.name).asClass, patch)
14591463

project/Scala2LibraryBootstrappedMiMaFilters.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ object Scala2LibraryBootstrappedMiMaFilters {
99
// Files that are not compiled in the bootstrapped library
1010
ProblemFilters.exclude[MissingClassProblem]("scala.AnyVal"),
1111

12+
// Overwritten inline methods
13+
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.Predef.assert"),
14+
1215
// Scala language features
1316
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.language.<clinit>"),
1417
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.language#experimental.<clinit>"),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ 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)
264-
throw new java.lang.AssertionError("assertion failed")
264+
scala.runtime.Scala3RunTime.assertFailed()
265265
}
266266

267267
/** Tests an expression, throwing an `AssertionError` if false.
@@ -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 = {
277+
transparent inline def assert(inline assertion: Boolean, inline message: => Any): Unit = {
278278
if (!assertion)
279-
throw new java.lang.AssertionError("assertion failed: "+ message)
279+
scala.runtime.Scala3RunTime.assertFailed(message)
280280
}
281281

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

0 commit comments

Comments
 (0)