Skip to content

Commit 1a5e97c

Browse files
committed
wip
1 parent e2db176 commit 1a5e97c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ class Definitions {
723723
lazy val InternalQuoted_patternHoleR: TermRef = InternalQuotedModule.requiredMethodRef("patternHole")
724724
def InternalQuoted_patternHole(implicit ctx: Context): Symbol = InternalQuoted_patternHoleR.symbol
725725
lazy val InternalQuoted_patternBindHoleAnnot: ClassSymbol = InternalQuotedModule.requiredClass("patternBindHole")
726+
lazy val InternalQuoted_patternTypeHole: Symbol = InternalQuotedModule.requiredType("patternTypeHole")
726727

727728
lazy val InternalQuotedMatcherModuleRef: TermRef = ctx.requiredModuleRef("scala.internal.quoted.Matcher")
728729
def InternalQuotedMatcherModule(implicit ctx: Context): Symbol = InternalQuotedMatcherModuleRef.symbol

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,12 +1943,22 @@ class Typer extends Namer
19431943
val quotedPt = if (exprPt.exists) exprPt.argTypesHi.head else defn.AnyType
19441944
val quoted1 = typedExpr(quoted, quotedPt)(quoteContext.addMode(Mode.QuotedPattern))
19451945
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))
19461956
val patType = defn.tupleType(splices.tpes.map(_.widen))
19471957
val splicePat = typed(untpd.Tuple(splices.map(untpd.TypedSplice(_))).withSpan(quoted.span), patType)
19481958
UnApply(
19491959
fun = ref(defn.InternalQuotedMatcher_unapplyR).appliedToType(patType),
19501960
implicits =
1951-
ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape) ::
1961+
ref(defn.InternalQuoted_exprQuoteR).appliedToType(shape.tpe).appliedTo(shape2) ::
19521962
implicitArgTree(defn.TastyReflectionType, tree.span) :: Nil,
19531963
patterns = splicePat :: Nil,
19541964
proto = pt)
@@ -1999,8 +2009,11 @@ class Typer extends Namer
19992009
}
20002010

20012011
/** 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+
}
20042017

20052018
/** Translate `${ t: Expr[T] }` into expression `t.splice` while tracking the quotation level in the context */
20062019
def typedSplice(tree: untpd.Splice, pt: Type)(implicit ctx: Context): Tree = track("typedSplice") {

0 commit comments

Comments
 (0)