diff --git a/tests/run/i5110/quoted_1.scala b/tests/run/i5110/quoted_1.scala new file mode 100644 index 000000000000..9be1181f3dcf --- /dev/null +++ b/tests/run/i5110/quoted_1.scala @@ -0,0 +1,16 @@ +import scala.quoted._ + +object Macro { + + class Boom extends Exception + + class Bomb { + throw new Boom + } + + inline def (boom: Bomb) foo(): Unit = () + + // By name Boom is used to elide the evaluation of the prefix + inline def (boom: => Bomb) bar(): Unit = () + +} diff --git a/tests/run/i5110/quoted_2.scala b/tests/run/i5110/quoted_2.scala new file mode 100644 index 000000000000..ce0adb2639b8 --- /dev/null +++ b/tests/run/i5110/quoted_2.scala @@ -0,0 +1,23 @@ +import scala.util.Try + +object Test { + import Macro._ + + def main(args: Array[String]): Unit = { + def bomb = new Bomb + new Bomb().bar() // Safely elided prefix + bomb.bar() // Safely elided prefix + shouldThrowBoom { new Bomb().foo() } + shouldThrowBoom { bomb.foo() } + + } + + def shouldThrowBoom(x: => Any): Unit = { + try { + x + ??? + } catch { + case ex: Boom => // OK + } + } +} diff --git a/tests/run/quote-elide-prefix/quoted_1.scala b/tests/run/quote-elide-prefix/quoted_1.scala new file mode 100644 index 000000000000..eff82921be1d --- /dev/null +++ b/tests/run/quote-elide-prefix/quoted_1.scala @@ -0,0 +1,9 @@ +import scala.quoted._ + +object Macro { + + // By name StringContext is used to elide the prefix + inline def (sc: => StringContext) ff (args: => Any*): String = ${ Macro.impl('sc, 'args) } + + def impl(sc: Expr[StringContext], args: Expr[Seq[Any]]): Expr[String] = '{ $args.mkString } +} diff --git a/tests/run/quote-elide-prefix/quoted_2.scala b/tests/run/quote-elide-prefix/quoted_2.scala new file mode 100644 index 000000000000..f200e1ee815e --- /dev/null +++ b/tests/run/quote-elide-prefix/quoted_2.scala @@ -0,0 +1,9 @@ + +object Test { + import Macro._ + + def main(args: Array[String]): Unit = { + def test = ff"Hello ${"World"}" + assert(test == "World") + } +}