Skip to content

Commit 0b9c396

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 0c56197 commit 0b9c396

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,14 @@ class Definitions {
14381438
)
14391439

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

project/Scala2LibraryBootstrappedMiMaFilters.scala

+3
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

+4-4
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)