Skip to content

Commit

Permalink
Configure _assert so that it doesn't affect Predef.assert
Browse files Browse the repository at this point in the history
This way it works the same in Scala 3 and 2.13.
  • Loading branch information
durban committed Jan 3, 2025
1 parent 93f7c4f commit 6a0c5f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ lazy val commonSettings = Seq[Setting[_]](
"-Xsource:3-cross",
"-Wnonunit-statement",
"-Wvalue-discard",
) ++ (if (assertionsEnabled.value) Nil else List("-Xelide-below", "2001"))
) ++ (if (assertionsEnabled.value) Nil else List("-Xelide-below", "1501"))
} else {
// 3.x:
List(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import scala.annotation.{ elidable, nowarn }
@nowarn("msg=elidable")
private[choam] abstract class ChoamUtils2 {

@elidable(elidable.ASSERTION)
@elidable(1500)
private[choam] final def _assert(ok: Boolean): Unit = {
if (!ok) {
throw new AssertionError
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ final class DisableAssertionsSpec extends BaseSpec {
_assert({ throw new Exception; false }) : @nowarn("cat=w-flag-dead-code")
}

test("Predef.assert should still work".fail) {
Predef.assert(false)
}

test("Predef.assert should still work (with message)".fail) {
Predef.assert(false, "foo")
}

test("munit assert should still work".fail) {
this.assert(false)
}

test("require(Boolean) should still work".fail) {
test("require should still work".fail) {
require(false)
}

test("require(Boolean, => Any) should still work".fail) {
test("require should still work (with message)".fail) {
require(false, "foo")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.annotation.{ elidable, nowarn }
@nowarn("msg=elidable")
private[choam] abstract class ChoamUtils {

@elidable(elidable.ASSERTION)
@elidable(1500)
private[choam] final def _assert(ok: Boolean): Unit = {
if (!ok) {
throw new AssertionError
Expand Down

0 comments on commit 6a0c5f8

Please sign in to comment.