File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -1180,8 +1180,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1180
1180
1181
1181
/** An extractor for typed splices */
1182
1182
object Splice {
1183
- def apply (tree : Tree )(implicit ctx : Context ): Tree =
1184
- ref(defn.InternalQuoted_exprSplice ).appliedTo(tree)
1183
+ def apply (tree : Tree )(implicit ctx : Context ): Tree = {
1184
+ val argType = tree.tpe.baseType(defn.QuotedExprClass ).argTypesHi.head
1185
+ ref(defn.InternalQuoted_exprSplice ).appliedToType(argType).appliedTo(tree)
1186
+ }
1185
1187
def unapply (tree : Tree )(implicit ctx : Context ): Option [Tree ] = tree match {
1186
1188
case Apply (fn, arg :: Nil ) if fn.symbol == defn.InternalQuoted_exprSplice => Some (arg)
1187
1189
case _ => None
Original file line number Diff line number Diff line change @@ -1963,7 +1963,7 @@ class Typer extends Namer
1963
1963
val exprTpt = ref(defn.QuotedExprType ).appliedToTypeTrees(tpt :: Nil )
1964
1964
transform(Splice (Typed (pat, exprTpt)))
1965
1965
case Splice (pat) =>
1966
- try tasty. TreePickler . Hole (patBuf.length, Nil )
1966
+ try holeForSplice(tree )
1967
1967
finally patBuf += pat
1968
1968
case _ =>
1969
1969
super .transform(tree)
@@ -1973,6 +1973,13 @@ class Typer extends Namer
1973
1973
(result, splitter.patBuf.toList)
1974
1974
}
1975
1975
1976
+ // TODO: Currently, a hole is expressed as interal.quoted.ExprSplice[T](???)
1977
+ // Settle on a different representation and apply Stagin
1978
+ def holeForSplice (splice : Tree )(implicit ctx : Context ): Tree = {
1979
+ val Apply (fn, arg) = splice
1980
+ tpd.cpy.Apply (splice)(fn, ref(defn.Predef_undefined ) :: Nil )
1981
+ }
1982
+
1976
1983
def givenReflection (implicit ctx : Context ): Tree = Literal (Constant (null )) // FIXME: fill in
1977
1984
1978
1985
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ object Test {
2
2
3
3
val x = ' {1 + 2 }
4
4
5
+ def f (x : Int ) = x
6
+
5
7
x match {
6
- case ' {1 + 2 } =>
7
- case _ =>
8
+ case ' {1 + 2 } => 0
9
+ case ' {f($x)} => x
8
10
}
9
11
}
You can’t perform that action at this time.
0 commit comments