Skip to content

Commit a3fbf5c

Browse files
committed
Fix bug in interpreter and add test cases
1 parent 3f8702b commit a3fbf5c

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class Interpreter(implicit ctx: Context) {
111111
private def paramsSig(sym: Symbol): List[Class[_]] = {
112112
sym.signature.paramsSig.map { param =>
113113
val paramString = param.toString
114-
if (paramString == defn.ByteClass.showFullName) classOf[Byte]
114+
if (paramString == defn.BooleanClass.showFullName) classOf[Boolean]
115+
else if (paramString == defn.ByteClass.showFullName) classOf[Byte]
115116
else if (paramString == defn.CharClass.showFullName) classOf[Char]
116117
else if (paramString == defn.ShortClass.showFullName) classOf[Short]
117118
else if (paramString == defn.IntClass.showFullName) classOf[Int]

tests/run/quote-and-splice.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
3
2+
3
3+
4
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
import scala.quoted._
2+
13
object Macros {
24

35
inline def macro1 = ~ macro1Impl
46
def macro1Impl = '(3)
57

8+
inline def macro2(inline p: Boolean) = ~ macro2Impl(p)
9+
def macro2Impl(p: Boolean) = if (p) '(3) else '(4)
10+
11+
inline def macro3(n: Int) = ~ macro3Impl('(n))
12+
def macro3Impl(p: Expr[Int]) = '{ 2 + ~p }
13+
14+
inline def power(inline n: Int, x: Double) = ~powerCode(n, '(x))
15+
16+
def powerCode(n: Int, x: Expr[Double]): Expr[Double] =
17+
if (n == 0) '(1.0)
18+
else if (n == 1) x
19+
else if (n % 2 == 0) '{ { val y = ~x * ~x; ~powerCode(n / 2, '(y)) } }
20+
else '{ ~x * ~powerCode(n - 1, x) }
621
}

tests/run/quote-and-splice/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ object Test {
33

44
def main(args: Array[String]): Unit = {
55
println(macro1)
6+
println(macro2(true))
7+
println(macro2(false))
8+
// FIXME value of type scala.quoted.Type[Int] does not take parameters
9+
// println(macro3(1))
10+
// println(power(1, 1))
11+
// println(power(2, 2))
12+
// println(power(3, 3))
613
}
714

815
}

0 commit comments

Comments
 (0)