Skip to content

Drop DottyPredef.assertFail. #10303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
val sources = List(
mkSource("assert(true)", "()"),
mkSource("assert(true, ???)", "()"),
mkSource("assert(false)", "assertFail()")
mkSource("assert(false)", "scala.runtime.Scala3RunTime.assertFailed()")
)
for (source <- sources)
checkBCode(source) { dir =>
Expand Down
1 change: 0 additions & 1 deletion docs/docs/internals/debug-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Here is the usually stacktrace for unresolved symbols in pickling:

```
[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
[error] at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
[error] at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:699)
[error] at dotty.tools.dotc.transform.Pickler.run$$anonfun$10$$anonfun$8(Pickler.scala:60)
[error] at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
Expand Down
7 changes: 2 additions & 5 deletions library/src/dotty/DottyPredef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ object DottyPredef {

inline final def assert(inline assertion: Boolean, inline message: => Any): Unit = {
if (!assertion)
assertFail(message)
scala.runtime.Scala3RunTime.assertFailed(message)
}

transparent inline final def assert(inline assertion: Boolean): Unit = {
if (!assertion)
assertFail()
scala.runtime.Scala3RunTime.assertFailed()
}

def assertFail(): Nothing = throw new java.lang.AssertionError("assertion failed")
def assertFail(message: => Any): Nothing = throw new java.lang.AssertionError("assertion failed: " + message)

inline final def implicitly[T](implicit ev: T): T = ev

/** Used to mark code blocks as being expressions, instead of being taken as part of anonymous classes and the like.
Expand Down
13 changes: 13 additions & 0 deletions library/src/scala/runtime/Scala3RunTime.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package scala.runtime

object Scala3RunTime:

// Called by inline def assert's. Extracted to minimize the bytecode size at call site.

def assertFailed(message: Any): Nothing =
throw new java.lang.AssertionError("assertion failed: " + message)

def assertFailed(): Nothing =
throw new java.lang.AssertionError("assertion failed")

end Scala3RunTime
2 changes: 1 addition & 1 deletion scala3doc/resources/dotty_res/scripts/hljs-scala3.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function highlightDotty(hljs) {
'if implicit import lazy match new object package private protected override return '+
'sealed then throw trait true try type val var while with yield =>> => ?=> <: >: _ ? <-',
literal: 'true false null this super',
built_in: '??? asInstanceOf isInstanceOf assert assertFail implicitly locally summon .nn'
built_in: '??? asInstanceOf isInstanceOf assert implicitly locally summon .nn'
}
const modifiers = 'abstract|final|implicit|override|private|protected|sealed'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ object BootstrappedStdLibTASYyTest:
def compileBlacklist = List[String](
// See #10048
// failed: java.lang.AssertionError: assertion failed: class Boolean
// at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/main-method-scheme-class-based.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class main extends MainAnnotation:
/** Issue an error, and return an uncallable getter */
private def error(msg: String): () => Nothing =
errors += msg
() => assertFail("trying to get invalid argument")
() => throw new AssertionError("trying to get invalid argument")

/** The next argument index */
private var argIdx: Int = 0
Expand Down
4 changes: 2 additions & 2 deletions tests/pos/matches.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Test:
case 3 => "?"
match
case "OK" =>
case "?" => assertFail()
case "?" => throw new AssertionError()

val x = 4
if 2 < 3
Expand All @@ -17,4 +17,4 @@ object Test:
case _ => false
then
println("ok")
end Test
end Test
2 changes: 1 addition & 1 deletion tests/run/Signals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BankAccount:
val b = myBalance()
myBalance() = b - amount
myBalance()
else assertFail("insufficient funds")
else throw new AssertionError("insufficient funds")
end BankAccount

@main def Test() =
Expand Down
2 changes: 1 addition & 1 deletion tests/run/Signals1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BankAccount:
val b = myBalance()
myBalance() = b - amount
myBalance()
else assertFail("insufficient funds")
else throw new AssertionError("insufficient funds")
end BankAccount

@main def Test() =
Expand Down
2 changes: 1 addition & 1 deletion tests/run/decorators/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class main extends EntryPoint.Annotation:
/** Issue an error, and return an uncallable getter */
private def error(msg: String): () => Nothing =
errors += msg
() => assertFail("trying to get invalid argument")
() => throw new AssertionError("trying to get invalid argument")

/** The next argument index */
private var argIdx: Int = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/run/enum-values.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum ClassOnly: // this should still generate the `ordinal` and `fromOrdinal` co
def cantFind[T](companion: FromOrdinal[T], ordinal: Int): Unit =
try
companion.fromOrdinal(ordinal)
assertFail(s"$companion.fromOrdinal(${ordinal}) did not fail")
throw new AssertionError(s"$companion.fromOrdinal(${ordinal}) did not fail")
catch
case e: java.lang.reflect.InvocationTargetException => // TODO: maybe reflect.Selectable should catch this?
assert(e.getCause.isInstanceOf[java.util.NoSuchElementException]
Expand Down
4 changes: 1 addition & 3 deletions tests/semanticdb/expect/inlinedefs.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package inlinedefs

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

def assertFail/*<-inlinedefs::FakePredef.assertFail().*/(): Nothing/*->scala::Nothing#*/ = throw new java.lang.AssertionError/*->java::lang::AssertionError#*//*->java::lang::AssertionError#`<init>`(+2).*/("assertion failed")

/** Super long padded documentation
* Lorem ipsum dolor sit amet, consectetur adipiscing elit,
* sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Expand All @@ -15,5 +13,5 @@ object FakePredef/*<-inlinedefs::FakePredef.*/:
*/
transparent inline final def assert/*<-inlinedefs::FakePredef.assert().*/(inline assertion/*<-inlinedefs::FakePredef.assert().(assertion)*/: Boolean/*->scala::Boolean#*/): Unit/*->scala::Unit#*/ = {
if (!assertion/*->inlinedefs::FakePredef.assert().(assertion)*//*->scala::Boolean#`unary_!`().*/)
assertFail/*->inlinedefs::FakePredef.assertFail().*/()
throw new java.lang.AssertionError/*->java::lang::AssertionError#*//*->java::lang::AssertionError#`<init>`(+2).*/("assertion failed")
}
4 changes: 1 addition & 3 deletions tests/semanticdb/expect/inlinedefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package inlinedefs

object FakePredef:

def assertFail(): Nothing = throw new java.lang.AssertionError("assertion failed")

/** Super long padded documentation
* Lorem ipsum dolor sit amet, consectetur adipiscing elit,
* sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Expand All @@ -15,5 +13,5 @@ object FakePredef:
*/
transparent inline final def assert(inline assertion: Boolean): Unit = {
if (!assertion)
assertFail()
throw new java.lang.AssertionError("assertion failed")
}
28 changes: 12 additions & 16 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3111,31 +3111,27 @@ Schema => SemanticDB v4
Uri => inlinedefs.scala
Text => empty
Language => Scala
Symbols => 4 entries
Occurrences => 15 entries
Symbols => 3 entries
Occurrences => 12 entries

Symbols:
inlinedefs/FakePredef. => final object FakePredef
inlinedefs/FakePredef.assert(). => final macro assert
inlinedefs/FakePredef.assert().(assertion) => param assertion
inlinedefs/FakePredef.assertFail(). => method assertFail

Occurrences:
[0:8..0:18): inlinedefs <- inlinedefs/
[2:7..2:17): FakePredef <- inlinedefs/FakePredef.
[4:6..4:16): assertFail <- inlinedefs/FakePredef.assertFail().
[4:20..4:27): Nothing -> scala/Nothing#
[4:40..4:44): java -> java/
[4:45..4:49): lang -> java/lang/
[4:50..4:64): AssertionError -> java/lang/AssertionError#
[4:64..4:64): -> java/lang/AssertionError#`<init>`(+2).
[15:31..15:37): assert <- inlinedefs/FakePredef.assert().
[15:45..15:54): assertion <- inlinedefs/FakePredef.assert().(assertion)
[15:56..15:63): Boolean -> scala/Boolean#
[15:66..15:70): Unit -> scala/Unit#
[16:9..16:18): assertion -> inlinedefs/FakePredef.assert().(assertion)
[16:18..16:18): -> scala/Boolean#`unary_!`().
[17:6..17:16): assertFail -> inlinedefs/FakePredef.assertFail().
[13:31..13:37): assert <- inlinedefs/FakePredef.assert().
[13:45..13:54): assertion <- inlinedefs/FakePredef.assert().(assertion)
[13:56..13:63): Boolean -> scala/Boolean#
[13:66..13:70): Unit -> scala/Unit#
[14:9..14:18): assertion -> inlinedefs/FakePredef.assert().(assertion)
[14:18..14:18): -> scala/Boolean#`unary_!`().
[15:16..15:20): java -> java/
[15:21..15:25): lang -> java/lang/
[15:26..15:40): AssertionError -> java/lang/AssertionError#
[15:40..15:40): -> java/lang/AssertionError#`<init>`(+2).

expect/local-file.scala
-----------------------
Expand Down