Skip to content

Commit e6babac

Browse files
authored
Merge pull request #3852 from dotty-staging/fix-interpreting-typed-trees
Fix interpretation of Typed trees
2 parents f90da9e + ef22a87 commit e6babac

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ class Interpreter(implicit ctx: Context) {
111111
val env2 = bindings.foldLeft(env)((acc, x) => interpretStat(x, acc))
112112
interpretTreeImpl(expansion, env2)
113113

114+
case Typed(expr, _) =>
115+
interpretTreeImpl(expr, env)
116+
114117
case _ =>
115118
// TODO Add more precise descriptions of why it could not be interpreted.
116119
// This should be done after the full interpreter is implemented.
117-
throw new StopInterpretation(s"Could not interpret ${tree.show}\n${tree}", tree.pos)
120+
throw new StopInterpretation(s"Could not interpret ${tree.show}. Consider extracting logic into a helper def.", tree.pos)
118121
}
119122
}
120123

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
true
2+
false
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import dotty.tools.dotc.ast.Trees.Import
2+
3+
import scala.quoted._
4+
object Macros {
5+
sealed trait Nat
6+
case object Z extends Nat
7+
case class S[N <: Nat]() extends Nat
8+
9+
inline def isZero(inline n: Int): Boolean = ~{
10+
if (n == 0) (true: Expr[Boolean])
11+
else (false: Expr[Boolean])
12+
}
13+
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Macros._
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
println(isZero(0))
5+
println(isZero(1))
6+
}
7+
}

0 commit comments

Comments
 (0)