Skip to content

All asserts in Quotes should give helpful error messages #20946

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

Closed
KacperFKorban opened this issue Jul 2, 2024 · 0 comments · Fixed by #21852
Closed

All asserts in Quotes should give helpful error messages #20946

KacperFKorban opened this issue Jul 2, 2024 · 0 comments · Fixed by #21852
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Milestone

Comments

@KacperFKorban
Copy link
Member

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.

@KacperFKorban KacperFKorban added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages labels Jul 2, 2024
@jchyb jchyb closed this as completed in b47f0f2 Nov 4, 2024
@WojciechMazur WojciechMazur added this to the 3.6.3 milestone Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants