Created
March 20, 2024 08:57
-
-
Save keynmol/e1c6549bf366e37138aa9ffdcd52e2ac to your computer and use it in GitHub Desktop.
TODO macro in Scala 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def myLazyWork(str: String) = | |
str match | |
case "hello" => println("yo") | |
case "world" => TODO("world is unhandled") | |
@main def hello = | |
myLazyWork("hello") | |
myLazyWork("world") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by this tweet: https://twitter.com/awesomekling/status/1770369132141121840 | |
import scala.quoted.* | |
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) } |
Author
keynmol
commented
Mar 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment