File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .tasty ._
3+
4+ object Macros {
5+
6+ inline def assert (condition : => Boolean ): Unit = $ { assertImpl(' {condition}, ' {" " }) }
7+
8+ def assertImpl (cond : Expr [Boolean ], clue : Expr [Any ])(implicit refl : Reflection ): Expr [Unit ] = {
9+ import refl ._
10+ val b = cond.unseal.underlyingArgument.seal[Boolean ]
11+ ' { scala.Predef .assert($b) }
12+ }
13+
14+ inline def thisLineNumber = $ { thisLineNumberImpl }
15+
16+ def thisLineNumberImpl (implicit refl : Reflection ): Expr [Int ] = {
17+ import refl ._
18+ refl.rootPosition.startLine.toExpr
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ object Test {
2+ import Macros ._
3+
4+ def main (args : Array [String ]): Unit = {
5+ val startLine = thisLineNumber
6+ assert(thisLineNumber == startLine + 1 )
7+ assert(thisLineNumber == startLine + 2 )
8+ scala.Predef .assert(thisLineNumber == startLine + 3 )
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments