Skip to content

Commit d1b2bab

Browse files
committed
WIP Type spliced expression directly
Also stop addapting `Expr[T]` to `Expr[Unit]` for simplicity.
1 parent 1a22b7c commit d1b2bab

File tree

9 files changed

+29
-9
lines changed

9 files changed

+29
-9
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,13 @@ class Typer extends Namer
19521952
ctx.warning("Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.", tree.sourcePos)
19531953
typed(innerExpr, pt)
19541954
case expr =>
1955-
typedApply(untpd.Apply(untpd.ref(defn.InternalQuoted_exprSpliceR), tree.expr), pt)(spliceContext).withSpan(tree.span)
1955+
val typedExpr = typed(tree.expr, defn.QuotedExprType.appliedTo(pt))(spliceContext)
1956+
typedExpr.tpe.widenTermRefExpr match {
1957+
case tp: AppliedType =>
1958+
tpd.ref(defn.InternalQuoted_exprSpliceR).appliedToType(tp.args.head).appliedTo(typedExpr).withSpan(tree.span)
1959+
case _ =>
1960+
EmptyTree
1961+
}
19561962
}
19571963
}
19581964

library/src-bootstrapped/scala/StagedTuple.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ object StagedTuple {
113113
tup.as[Tuple5[_, _, _, _, _]].bind(t => '{Tuple4($t._2, $t._3, $t._4, $t._5)})
114114
case Some(n) if n > 5 =>
115115
val arr = toArrayStaged(tup, size)
116-
fromArrayStaged('{ $arr.tail }, Some(n - 1))
116+
// TODO remove ascriptions
117+
fromArrayStaged('{ ($arr: Array[Object]).tail }, Some(n - 1))
117118
case None =>
118119
'{dynamicTail($tup)}
119120
}
@@ -203,7 +204,8 @@ object StagedTuple {
203204
if (!specialize) '{dynamic_++[Self, That]($self, $that)}
204205
else {
205206
def genericConcat(xs: Expr[Tuple], ys: Expr[Tuple]): Expr[Tuple] =
206-
fromArrayStaged[Tuple]('{${ toArrayStaged(xs, None) } ++ (${ toArrayStaged(ys, None) }: Array[Object])}, None)
207+
// TODO remove ascriptions
208+
fromArrayStaged[Tuple]('{(${ toArrayStaged(xs, None) }: Array[Object]) ++ (${ toArrayStaged(ys, None) }: Array[Object])}, None)
207209

208210
val res = selfSize match {
209211
case Some(0) =>

tests/neg/i4493-b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Index[K]
22
object Index {
3-
inline def succ[K](x: K): Unit = ${ // error
3+
inline def succ[K](x: K): Index[K] = ${ // error
44
implicit val t: quoted.Type[K] = '[K]
55
'{new Index[K]}
66
}

tests/neg/i4493.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Index[K]
22
object Index {
3-
inline def succ[K]: Unit = ${ // error
3+
inline def succ[K]: Index[K] = ${ // error
44
implicit val t: quoted.Type[K] = '[K]
55
'{new Index[K]}
66
}

tests/neg/quote-interpolator-core-old.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object FInterpolation {
1919
def fInterpolation(sc: StringContext, args: Seq[Expr[Any]]): Expr[String] = {
2020
val str: Expr[String] = sc.parts.mkString("").toExpr
2121
val args1: Expr[Seq[Any]] = liftSeq(args)
22-
'{ $str.format($args1: _*) }
22+
'{ ($str: String).format($args1: _*) } // FIXME remove ascription
2323
}
2424

2525
def hello = "hello"

tests/pos/i3912-2/i3912_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22

33
object Macros {
4-
inline def foo2(): Unit = ${ impl() }
4+
inline def foo2(): Int = ${ impl() }
55

66
def impl(): Expr[Int] = '{1}
77
}

tests/pos/i4493-c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Index[K]
22
object Index {
3-
inline def succ[K]: Unit = ${
3+
inline def succ[K]: Index[K] = ${
44
'{new Index[K]}
55
}
66
}

tests/pos/quote-string-format.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
3+
class Test {
4+
5+
def foo: Expr[String] = {
6+
val str: Expr[String] = ???
7+
val args1: Expr[Seq[Any]] = ???
8+
'{ ($str: String).format($args1: _*) }
9+
// '{ $str.format($args1: _*) } // FIXME
10+
}
11+
12+
}

tests/run/quote-change-owner/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.quoted._
22
object Macros {
33
inline def assert2(expr: => Boolean): Unit = ${ assertImpl('expr) }
44
def assertImpl(expr: Expr[Boolean]) = '{
5-
def foo(): Unit = $expr
5+
def foo(): Unit = { $expr; () }
66
foo()
77
}
88
}

0 commit comments

Comments
 (0)