Closed
Description
Compiler version
main
(3.5.1-RC1-bin-20240628-1efbb92-NIGHTLY
)
Minimized example
//> using scala 3.5.1-RC1-bin-20240628-1efbb92-NIGHTLY
// _2.scala
inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }
@main
def run =
macroWithAssertFailing[Int](123)
Comment out the Ref
expression and uncomment the TypeIdent
one for the second error.
// _1.scala
import scala.quoted.*
def macroWithAssertFailingImpl[T: Type](t: Expr[T])(using Quotes): Expr[Unit] = {
import quotes.reflect.*
Ref(TypeRepr.of[T].typeSymbol) // error 1
// TypeIdent(t.asTerm.symbol) // error 2
'{()}
}
Output Error/Warning message
Error 1
-- Error: macroasserts/_2.scala:8:29 ----------------------------
8 | macroWithAssertFailing[Int](123)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|Exception occurred while executing macro expansion.
|java.lang.AssertionError: assertion failed
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:475)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Ref$.apply(QuotesImpl.scala:474)
| at _1$package$.macroWithAssertFailingImpl(_1.scala:8)
|
|-----------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from _2.scala:4
4 |inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----------------------------------------------------------------------------
Error 2
-- Error: macroasserts/_2.scala:8:29 ----------------------------
8 | macroWithAssertFailing[Int](123)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|Exception occurred while executing macro expansion.
|java.lang.AssertionError: assertion failed
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1165)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$TypeIdent$.apply(QuotesImpl.scala:1164)
| at _1$package$.macroWithAssertFailingImpl(_1.scala:10)
|
|-----------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from _2.scala:4
4 |inline def macroWithAssertFailing[T](t: T): Unit = ${ macroWithAssertFailingImpl[T]('t) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-----------------------------------------------------------------------------
Why this Error/Warning was not helpful
The assert should provide a useful message about why it failed.
Asserts in Quotes
that are missing messages:
It might also be useful to check other assert messages if they can be improved.