Skip to content

Commit bc51ec8

Browse files
authored
Merge pull request #6123 from dotty-staging/fix-#5110
Fix #5110: Add regression tests
2 parents f926147 + 4fff070 commit bc51ec8

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

tests/run/i5110/quoted_1.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

tests/run/i5110/quoted_2.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

0 commit comments

Comments
 (0)