Skip to content

Commit cd613e7

Browse files
authored
Merge pull request #10303 from dotty-staging/drop-assertFail
Drop DottyPredef.assertFail.
2 parents df27dcd + e0728b3 commit cd613e7

File tree

15 files changed

+38
-38
lines changed

15 files changed

+38
-38
lines changed

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
5454
val sources = List(
5555
mkSource("assert(true)", "()"),
5656
mkSource("assert(true, ???)", "()"),
57-
mkSource("assert(false)", "assertFail()")
57+
mkSource("assert(false)", "scala.runtime.Scala3RunTime.assertFailed()")
5858
)
5959
for (source <- sources)
6060
checkBCode(source) { dir =>

docs/docs/internals/debug-macros.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Here is the usually stacktrace for unresolved symbols in pickling:
3737

3838
```
3939
[error] java.lang.AssertionError: assertion failed: unresolved symbols: value pos (line 5565) when pickling scalatest/scalatest-test.dotty/target/scala-0.17/src_managed/test/org/scalatest/AssertionsSpec.scala
40-
[error] at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
4140
[error] at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:699)
4241
[error] at dotty.tools.dotc.transform.Pickler.run$$anonfun$10$$anonfun$8(Pickler.scala:60)
4342
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)

library/src/dotty/DottyPredef.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@ object DottyPredef {
55

66
inline final def assert(inline assertion: Boolean, inline message: => Any): Unit = {
77
if (!assertion)
8-
assertFail(message)
8+
scala.runtime.Scala3RunTime.assertFailed(message)
99
}
1010

1111
transparent inline final def assert(inline assertion: Boolean): Unit = {
1212
if (!assertion)
13-
assertFail()
13+
scala.runtime.Scala3RunTime.assertFailed()
1414
}
1515

16-
def assertFail(): Nothing = throw new java.lang.AssertionError("assertion failed")
17-
def assertFail(message: => Any): Nothing = throw new java.lang.AssertionError("assertion failed: " + message)
18-
1916
inline final def implicitly[T](implicit ev: T): T = ev
2017

2118
/** Used to mark code blocks as being expressions, instead of being taken as part of anonymous classes and the like.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package scala.runtime
2+
3+
object Scala3RunTime:
4+
5+
// Called by inline def assert's. Extracted to minimize the bytecode size at call site.
6+
7+
def assertFailed(message: Any): Nothing =
8+
throw new java.lang.AssertionError("assertion failed: " + message)
9+
10+
def assertFailed(): Nothing =
11+
throw new java.lang.AssertionError("assertion failed")
12+
13+
end Scala3RunTime

scala3doc/resources/dotty_res/scripts/hljs-scala3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function highlightDotty(hljs) {
2525
'if implicit import lazy match new object package private protected override return '+
2626
'sealed then throw trait true try type val var while with yield =>> => ?=> <: >: _ ? <-',
2727
literal: 'true false null this super',
28-
built_in: '??? asInstanceOf isInstanceOf assert assertFail implicitly locally summon .nn'
28+
built_in: '??? asInstanceOf isInstanceOf assert implicitly locally summon .nn'
2929
}
3030
const modifiers = 'abstract|final|implicit|override|private|protected|sealed'
3131

stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ object BootstrappedStdLibTASYyTest:
146146
def compileBlacklist = List[String](
147147
// See #10048
148148
// failed: java.lang.AssertionError: assertion failed: class Boolean
149-
// at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
150149
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
151150
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
152151
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)

tests/pos/main-method-scheme-class-based.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class main extends MainAnnotation:
6262
/** Issue an error, and return an uncallable getter */
6363
private def error(msg: String): () => Nothing =
6464
errors += msg
65-
() => assertFail("trying to get invalid argument")
65+
() => throw new AssertionError("trying to get invalid argument")
6666

6767
/** The next argument index */
6868
private var argIdx: Int = 0

tests/pos/matches.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Test:
55
case 3 => "?"
66
match
77
case "OK" =>
8-
case "?" => assertFail()
8+
case "?" => throw new AssertionError()
99

1010
val x = 4
1111
if 2 < 3
@@ -17,4 +17,4 @@ object Test:
1717
case _ => false
1818
then
1919
println("ok")
20-
end Test
20+
end Test

tests/run/Signals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BankAccount:
5353
val b = myBalance()
5454
myBalance() = b - amount
5555
myBalance()
56-
else assertFail("insufficient funds")
56+
else throw new AssertionError("insufficient funds")
5757
end BankAccount
5858

5959
@main def Test() =

tests/run/Signals1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BankAccount:
6666
val b = myBalance()
6767
myBalance() = b - amount
6868
myBalance()
69-
else assertFail("insufficient funds")
69+
else throw new AssertionError("insufficient funds")
7070
end BankAccount
7171

7272
@main def Test() =

tests/run/decorators/main.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class main extends EntryPoint.Annotation:
3232
/** Issue an error, and return an uncallable getter */
3333
private def error(msg: String): () => Nothing =
3434
errors += msg
35-
() => assertFail("trying to get invalid argument")
35+
() => throw new AssertionError("trying to get invalid argument")
3636

3737
/** The next argument index */
3838
private var argIdx: Int = 0

tests/run/enum-values.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ enum ClassOnly: // this should still generate the `ordinal` and `fromOrdinal` co
5555
def cantFind[T](companion: FromOrdinal[T], ordinal: Int): Unit =
5656
try
5757
companion.fromOrdinal(ordinal)
58-
assertFail(s"$companion.fromOrdinal(${ordinal}) did not fail")
58+
throw new AssertionError(s"$companion.fromOrdinal(${ordinal}) did not fail")
5959
catch
6060
case e: java.lang.reflect.InvocationTargetException => // TODO: maybe reflect.Selectable should catch this?
6161
assert(e.getCause.isInstanceOf[java.util.NoSuchElementException]

tests/semanticdb/expect/inlinedefs.expect.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package inlinedefs
22

33
object FakePredef/*<-inlinedefs::FakePredef.*/:
44

5-
def assertFail/*<-inlinedefs::FakePredef.assertFail().*/(): Nothing/*->scala::Nothing#*/ = throw new java.lang.AssertionError/*->java::lang::AssertionError#*//*->java::lang::AssertionError#`<init>`(+2).*/("assertion failed")
6-
75
/** Super long padded documentation
86
* Lorem ipsum dolor sit amet, consectetur adipiscing elit,
97
* sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
@@ -15,5 +13,5 @@ object FakePredef/*<-inlinedefs::FakePredef.*/:
1513
*/
1614
transparent inline final def assert/*<-inlinedefs::FakePredef.assert().*/(inline assertion/*<-inlinedefs::FakePredef.assert().(assertion)*/: Boolean/*->scala::Boolean#*/): Unit/*->scala::Unit#*/ = {
1715
if (!assertion/*->inlinedefs::FakePredef.assert().(assertion)*//*->scala::Boolean#`unary_!`().*/)
18-
assertFail/*->inlinedefs::FakePredef.assertFail().*/()
16+
throw new java.lang.AssertionError/*->java::lang::AssertionError#*//*->java::lang::AssertionError#`<init>`(+2).*/("assertion failed")
1917
}

tests/semanticdb/expect/inlinedefs.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package inlinedefs
22

33
object FakePredef:
44

5-
def assertFail(): Nothing = throw new java.lang.AssertionError("assertion failed")
6-
75
/** Super long padded documentation
86
* Lorem ipsum dolor sit amet, consectetur adipiscing elit,
97
* sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
@@ -15,5 +13,5 @@ object FakePredef:
1513
*/
1614
transparent inline final def assert(inline assertion: Boolean): Unit = {
1715
if (!assertion)
18-
assertFail()
16+
throw new java.lang.AssertionError("assertion failed")
1917
}

tests/semanticdb/metac.expect

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,31 +3111,27 @@ Schema => SemanticDB v4
31113111
Uri => inlinedefs.scala
31123112
Text => empty
31133113
Language => Scala
3114-
Symbols => 4 entries
3115-
Occurrences => 15 entries
3114+
Symbols => 3 entries
3115+
Occurrences => 12 entries
31163116

31173117
Symbols:
31183118
inlinedefs/FakePredef. => final object FakePredef
31193119
inlinedefs/FakePredef.assert(). => final macro assert
31203120
inlinedefs/FakePredef.assert().(assertion) => param assertion
3121-
inlinedefs/FakePredef.assertFail(). => method assertFail
31223121

31233122
Occurrences:
31243123
[0:8..0:18): inlinedefs <- inlinedefs/
31253124
[2:7..2:17): FakePredef <- inlinedefs/FakePredef.
3126-
[4:6..4:16): assertFail <- inlinedefs/FakePredef.assertFail().
3127-
[4:20..4:27): Nothing -> scala/Nothing#
3128-
[4:40..4:44): java -> java/
3129-
[4:45..4:49): lang -> java/lang/
3130-
[4:50..4:64): AssertionError -> java/lang/AssertionError#
3131-
[4:64..4:64): -> java/lang/AssertionError#`<init>`(+2).
3132-
[15:31..15:37): assert <- inlinedefs/FakePredef.assert().
3133-
[15:45..15:54): assertion <- inlinedefs/FakePredef.assert().(assertion)
3134-
[15:56..15:63): Boolean -> scala/Boolean#
3135-
[15:66..15:70): Unit -> scala/Unit#
3136-
[16:9..16:18): assertion -> inlinedefs/FakePredef.assert().(assertion)
3137-
[16:18..16:18): -> scala/Boolean#`unary_!`().
3138-
[17:6..17:16): assertFail -> inlinedefs/FakePredef.assertFail().
3125+
[13:31..13:37): assert <- inlinedefs/FakePredef.assert().
3126+
[13:45..13:54): assertion <- inlinedefs/FakePredef.assert().(assertion)
3127+
[13:56..13:63): Boolean -> scala/Boolean#
3128+
[13:66..13:70): Unit -> scala/Unit#
3129+
[14:9..14:18): assertion -> inlinedefs/FakePredef.assert().(assertion)
3130+
[14:18..14:18): -> scala/Boolean#`unary_!`().
3131+
[15:16..15:20): java -> java/
3132+
[15:21..15:25): lang -> java/lang/
3133+
[15:26..15:40): AssertionError -> java/lang/AssertionError#
3134+
[15:40..15:40): -> java/lang/AssertionError#`<init>`(+2).
31393135

31403136
expect/local-file.scala
31413137
-----------------------

0 commit comments

Comments
 (0)