@@ -1943,12 +1943,22 @@ class Typer extends Namer
1943
1943
val quotedPt = if (exprPt.exists) exprPt.argTypesHi.head else defn.AnyType
1944
1944
val quoted1 = typedExpr(quoted, quotedPt)(quoteContext.addMode(Mode .QuotedPattern ))
1945
1945
val (shape, splices) = splitQuotePattern(quoted1)
1946
+ val typeBindings = splices.collect {
1947
+ case t if t.tpe.derivesFrom(defn.QuotedTypeClass ) =>
1948
+ t.tpe.widen.argTypesHi.head.typeSymbol
1949
+ }
1950
+ val inQuoteTypeBinding = typeBindings.map { sym =>
1951
+ ctx.newSymbol(sym.owner, (sym.name + " $$$" ).toTypeName, // TODO remove $$$, just there for debugging
1952
+ EmptyFlags , sym.info, coord = sym.coord)
1953
+ }
1954
+ val shape2 =
1955
+ seq(inQuoteTypeBinding.map(TypeDef ), shape.subst(typeBindings, inQuoteTypeBinding))
1946
1956
val patType = defn.tupleType(splices.tpes.map(_.widen))
1947
1957
val splicePat = typed(untpd.Tuple (splices.map(untpd.TypedSplice (_))).withSpan(quoted.span), patType)
1948
1958
UnApply (
1949
1959
fun = ref(defn.InternalQuotedMatcher_unapplyR ).appliedToType(patType),
1950
1960
implicits =
1951
- ref(defn.InternalQuoted_exprQuoteR ).appliedToType(shape.tpe).appliedTo(shape ) ::
1961
+ ref(defn.InternalQuoted_exprQuoteR ).appliedToType(shape.tpe).appliedTo(shape2 ) ::
1952
1962
implicitArgTree(defn.TastyReflectionType , tree.span) :: Nil ,
1953
1963
patterns = splicePat :: Nil ,
1954
1964
proto = pt)
@@ -1999,8 +2009,11 @@ class Typer extends Namer
1999
2009
}
2000
2010
2001
2011
/** A hole the shape pattern of a quoted.Matcher.unapply, representing a splice */
2002
- def patternHole (splice : Tree )(implicit ctx : Context ): Tree =
2003
- ref(defn.InternalQuoted_patternHoleR ).appliedToType(splice.tpe).withSpan(splice.span)
2012
+ def patternHole (splice : Tree )(implicit ctx : Context ): Tree = {
2013
+ val Splice (pat) = splice
2014
+ if (pat.tpe.derivesFrom(defn.QuotedTypeClass )) AppliedTypeTree (ref(defn.InternalQuoted_patternTypeHole ), TypeTree (splice.tpe) :: Nil ).withSpan(splice.span)
2015
+ else ref(defn.InternalQuoted_patternHoleR ).appliedToType(splice.tpe).withSpan(splice.span)
2016
+ }
2004
2017
2005
2018
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
2006
2019
def typedSplice (tree : untpd.Splice , pt : Type )(implicit ctx : Context ): Tree = track(" typedSplice" ) {
0 commit comments