Skip to content

Commit 5437c00

Browse files
authored
Implement an internal "assertShort" utility (#16164)
I'm often implementing against an assertion, for instance in TreeChecker. While implementing a fix I add some extra output. So it's useful for me to suppress the full page of stacktrace that that assert typically emits, so I can roundtrip without having to scroll back up.
2 parents c37b165 + 75471fb commit 5437c00

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/src/dotty/tools/package.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ package object tools {
4242

4343
def unreachable(x: Any = "<< this case was declared unreachable >>"): Nothing =
4444
throw new MatchError(x)
45+
46+
transparent inline def assertShort(inline assertion: Boolean, inline message: Any = null): Unit =
47+
if !assertion then
48+
val msg = message
49+
val e = if msg == null then AssertionError() else AssertionError("assertion failed: " + msg)
50+
e.setStackTrace(Array())
51+
throw e
4552
}

0 commit comments

Comments
 (0)