Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1132,19 +1132,14 @@ class TreeUnpickler(reader: TastyReader,
val idx = readNat()
val args = until(end)(readTerm())
val splice = splices(idx)

val reifiedArgs = args.map(arg => if (arg.isTerm) new TreeExpr(arg) else new TreeType(arg))
if (isType) {
val quotedType =
if (args.isEmpty) splice.asInstanceOf[quoted.Type[_]]
else splice.asInstanceOf[Seq[Any] => quoted.Type[_]](args.map(tree => new TreeType(tree)))
val quotedType = splice.asInstanceOf[Seq[Any] => quoted.Type[_]](reifiedArgs)
PickledQuotes.quotedTypeToTree(quotedType)
} else {
val quotedExpr =
if (args.isEmpty) splice.asInstanceOf[quoted.Expr[_]]
else splice.asInstanceOf[Seq[Any] => quoted.Expr[_]](args.map(tree => new TreeExpr(tree)))
val quotedExpr = splice.asInstanceOf[Seq[Any] => quoted.Expr[_]](reifiedArgs)
PickledQuotes.quotedExprToTree(quotedExpr)
}

}

// ------ Setting positions ------------------------------------------------
Expand Down
247 changes: 174 additions & 73 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions tests/neg/i4044a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.quoted._

class Test {

val a = '(1)
'{
a // error
~a
'(~a) // error
'( '(~a) ) // error
}

}
18 changes: 18 additions & 0 deletions tests/neg/i4044b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scala.quoted._

class Test {

'{

val b = '(3)

'{
b // error
~(b)
~('(b)) // error
'( '(~b) ) // error
}

}

}
1 change: 1 addition & 0 deletions tests/run-with-compiler/i4044a.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
17 changes: 17 additions & 0 deletions tests/run-with-compiler/i4044a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

class Foo {
def foo: Unit = {
val e: Expr[Int] = '(3)
val q = '{ ~( '{ ~e } ) }
println(q.show)
}
}

object Test {
def main(args: Array[String]): Unit = {
val f = new Foo
f.foo
}
}
5 changes: 5 additions & 0 deletions tests/run-with-compiler/i4044b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
var x: Int = 4
x = 3
x
}
27 changes: 27 additions & 0 deletions tests/run-with-compiler/i4044b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

sealed abstract class VarRef[T] {
def update(expr: Expr[T]): Expr[Unit]
def expr: Expr[T]
}

object VarRef {
def apply[T: Type, U](init: Expr[T])(body: VarRef[T] => Expr[U]): Expr[U] = '{
var x = ~init
~body(
new VarRef {
def update(e: Expr[T]): Expr[Unit] = '{ x = ~e }
def expr: Expr[T] = '(x)
}
)
}

}

object Test {
def main(args: Array[String]): Unit = {
val q = VarRef(4)(varRef => '{ ~varRef.update(3); ~varRef.expr })
println(q.show)
}
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/i4044c.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
16 changes: 16 additions & 0 deletions tests/run-with-compiler/i4044c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

class Foo {
def foo: Unit = {
val q = '{ ~( '{ ~( '{ 5 } ) } ) }
println(q.show)
}
}

object Test {
def main(args: Array[String]): Unit = {
val f = new Foo
f.foo
}
}
5 changes: 5 additions & 0 deletions tests/run-with-compiler/i4044d.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
evaluating inner quote
{
val b: Int = 3
b.+(3)
}
25 changes: 25 additions & 0 deletions tests/run-with-compiler/i4044d.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

class Foo {
def foo: Unit = {
val a: Expr[Int] = '(3)
val q: Expr[Int] = '{
val b = 3
~{
println("evaluating inner quote")
'{
b + ~a
}
}
}
println(q.show)
}
}

object Test {
def main(args: Array[String]): Unit = {
val f = new Foo
f.foo
}
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/i4044e.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.+(5).asInstanceOf[Int]
19 changes: 19 additions & 0 deletions tests/run-with-compiler/i4044e.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

class Foo {
def foo: Unit = {
val e: Expr[Int] = '(3)
val f: Expr[Int] = '(5)
val t: Type[Int] = '[Int]
val q = '{ ~( '{ (~e + ~f).asInstanceOf[~t] } ) }
println(q.show)
}
}

object Test {
def main(args: Array[String]): Unit = {
val f = new Foo
f.foo
}
}
5 changes: 5 additions & 0 deletions tests/run-with-compiler/i4044f.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
val e1: Int = 3
val f1: Int = 5
e1.+(2).+(f1)
}
26 changes: 26 additions & 0 deletions tests/run-with-compiler/i4044f.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import scala.quoted._
import dotty.tools.dotc.quoted.Toolbox._

class Foo {
def foo: Unit = {
val e: Expr[Int] = '(3)
val f: Expr[Int] = '(5)
def foo(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{ ~x + ~y }
val q = '{
val e1 = ~e
val f1 = ~f
~{
val u = '(2)
foo('{e1 + ~u}, '(f1))
}
}
println(q.show)
}
}

object Test {
def main(args: Array[String]): Unit = {
val f = new Foo
f.foo
}
}
7 changes: 7 additions & 0 deletions tests/run-with-compiler/quote-lambda.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

object Test {
def main(args: Array[String]): Unit = {
'{ (x: Int) => ~('(x)) }
}
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/quote-nested-1.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<special-ops>.'[Int](3)
9 changes: 9 additions & 0 deletions tests/run-with-compiler/quote-nested-1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import quoted._
import dotty.tools.dotc.quoted.Toolbox._

object Test {
def main(args: Array[String]): Unit = {
val q = '{ '(3) }
println(q.show)
}
}
4 changes: 4 additions & 0 deletions tests/run-with-compiler/quote-nested-2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
val a: quoted.Expr[Int] = <special-ops>.'[Int](4)
<special-ops>.'[Int](a.unary_~)
}
13 changes: 13 additions & 0 deletions tests/run-with-compiler/quote-nested-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import quoted._
import dotty.tools.dotc.quoted.Toolbox._

object Test {
def main(args: Array[String]): Unit = {
val q = '{
val a = '(4)
'(~a)
}

println(q.show)
}
}
7 changes: 7 additions & 0 deletions tests/run-with-compiler/quote-nested-3.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
type T = String
val x: String = "foo"
val z: T = x
()
x: String
}
19 changes: 19 additions & 0 deletions tests/run-with-compiler/quote-nested-3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import quoted._
import dotty.tools.dotc.quoted.Toolbox._

object Test {
def main(args: Array[String]): Unit = {

val q = '{
type T = String
val x = "foo"
~{
val y = '(x)
'{ val z: T = ~y }
}
x
}

println(q.show)
}
}
4 changes: 4 additions & 0 deletions tests/run-with-compiler/quote-nested-4.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
val t: quoted.Type[String] = <special-ops>.type_'[String]
t: quoted.Type[String]
}
13 changes: 13 additions & 0 deletions tests/run-with-compiler/quote-nested-4.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import quoted._
import dotty.tools.dotc.quoted.Toolbox._

object Test {
def main(args: Array[String]): Unit = {
val q = '{
val t = '[String]
t
}

println(q.show)
}
}
4 changes: 4 additions & 0 deletions tests/run-with-compiler/quote-nested-5.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
val a: quoted.Expr[Int] = <special-ops>.'[Int](4)
<special-ops>.'[Int](a.unary_~)
}
16 changes: 16 additions & 0 deletions tests/run-with-compiler/quote-nested-5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import quoted._
import dotty.tools.dotc.quoted.Toolbox._

object Test {
def main(args: Array[String]): Unit = {
val q = '{
val a = '(4)
~('{
'(~a)
})

}

println(q.show)
}
}