Skip to content

Instantly share code, notes, and snippets.

@keynmol
Last active July 16, 2026 10:16
Show Gist options
  • Select an option

  • Save keynmol/59a9e3e78c3b33c75b573b6d07e2ac18 to your computer and use it in GitHub Desktop.

Select an option

Save keynmol/59a9e3e78c3b33c75b573b6d07e2ac18 to your computer and use it in GitHub Desktop.
TODO and IMPROVE macros
import scala.quoted.*
/** This macro produces a compiler warning at use site AND throws at runtime if
* the code is ever reached
*
* @param msg
* @return
*/
transparent inline def TODO(inline msg: String) =
${ todoImpl('msg) }
private class You_fucked_around_and_found_out(msg: String)
extends RuntimeException(msg)
private def todoImpl(msg: Expr[String])(using Quotes): Expr[Any] =
val value = msg.valueOrAbort
quotes.reflect.report.warning(s"TODO: $value")
'{ throw new You_fucked_around_and_found_out($msg) }
end todoImpl
/** Use this macro to emit a compiler warning with a meaningful message (it does
* nothing at runtime)
*
* @param msg
* @return
*/
transparent inline def IMPROVE(inline msg: String) =
${ improveImpl('msg) }
private def improveImpl(msg: Expr[String])(using Quotes): Expr[Any] =
val value = msg.valueOrAbort
quotes.reflect.report.warning(s"TODO: $value")
'{ () }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment