From 4fff07013f545f0c9dcac33b36ecf7d61637c448 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 20 Mar 2019 13:53:31 +0100 Subject: [PATCH] Fix #5110: Add regression tests With the new syntax for extension method we can create a by name prefix which is elided if not used. --- tests/run/i5110/quoted_1.scala | 16 ++++++++++++++ tests/run/i5110/quoted_2.scala | 23 +++++++++++++++++++++ tests/run/quote-elide-prefix/quoted_1.scala | 9 ++++++++ tests/run/quote-elide-prefix/quoted_2.scala | 9 ++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/run/i5110/quoted_1.scala create mode 100644 tests/run/i5110/quoted_2.scala create mode 100644 tests/run/quote-elide-prefix/quoted_1.scala create mode 100644 tests/run/quote-elide-prefix/quoted_2.scala 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") + } +}