Skip to content

Commit caa2bc5

Browse files
authored
Merge pull request #3267 from dotty-staging/micro-optimizations-1
Avoid creating closure for asserts
2 parents 7c8f557 + d852465 commit caa2bc5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

library/src/dotty/DottyPredef.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ object DottyPredef {
2424
* `discardForView` from two to one.
2525
*/
2626
abstract class ImplicitConverter[-T, +U] extends Function1[T, U]
27+
28+
@inline final def assert(assertion: Boolean, message: => Any): Unit = {
29+
if (!assertion)
30+
assertFail(message)
31+
}
32+
33+
@inline final def assert(assertion: Boolean): Unit = {
34+
if (!assertion)
35+
assertFail()
36+
}
37+
38+
final def assertFail(): Unit = throw new java.lang.AssertionError("assertion failed")
39+
final def assertFail(message: => Any): Unit = throw new java.lang.AssertionError("assertion failed: " + message)
40+
2741
}

tests/neg/nopredef.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Predef.{assert => _}
2+
import dotty.DottyPredef.{assert => _}
23

34
object Test {
45
assert("asdf" == "asdf") // error: not found assert

0 commit comments

Comments
 (0)