File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+
3+ object Macro {
4+
5+ class Boom extends Exception
6+
7+ class Bomb {
8+ throw new Boom
9+ }
10+
11+ inline def (boom : Bomb ) foo(): Unit = ()
12+
13+ // By name Boom is used to elide the evaluation of the prefix
14+ inline def (boom : => Bomb ) bar(): Unit = ()
15+
16+ }
Original file line number Diff line number Diff line change 1+ import scala .util .Try
2+
3+ object Test {
4+ import Macro ._
5+
6+ def main (args : Array [String ]): Unit = {
7+ def bomb = new Bomb
8+ new Bomb ().bar() // Safely elided prefix
9+ bomb.bar() // Safely elided prefix
10+ shouldThrowBoom { new Bomb ().foo() }
11+ shouldThrowBoom { bomb.foo() }
12+
13+ }
14+
15+ def shouldThrowBoom (x : => Any ): Unit = {
16+ try {
17+ x
18+ ???
19+ } catch {
20+ case ex : Boom => // OK
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+
3+ object Macro {
4+
5+ // By name StringContext is used to elide the prefix
6+ inline def (sc : => StringContext ) ff (args : => Any * ): String = $ { Macro .impl(' sc , ' args ) }
7+
8+ def impl (sc : Expr [StringContext ], args : Expr [Seq [Any ]]): Expr [String ] = ' { $args.mkString }
9+ }
Original file line number Diff line number Diff line change 1+
2+ object Test {
3+ import Macro ._
4+
5+ def main (args : Array [String ]): Unit = {
6+ def test = ff " Hello ${" World" }"
7+ assert(test == " World" )
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments