Skip to content

Commit 92e0f01

Browse files
committed
WIP
1 parent 7ae170b commit 92e0f01

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
150150
/** Is a reference to a class but not `this.type` */
151151
def isClassRef = sym.isClass && !tp.isInstanceOf[ThisType]
152152

153-
if (sym.exists && !sym.isStaticOwner && !isClassRef && !levelOK(sym))
153+
if (sym.exists && !sym.isStaticOwner && !isClassRef && !levelOK(sym) &&
154+
!sym.hasAnnotation(defn.InternalQuoted_patternBindHoleAnnot) // FIXME this is a workaround
155+
)
154156
tryHeal(sym, tp, pos)
155157
else
156158
None

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,14 +1979,16 @@ class Typer extends Namer
19791979
val ctx0 = ctx
19801980

19811981
val typeBindings: collection.mutable.Map[Symbol, Bind] = collection.mutable.Map.empty
1982+
def getBinding(sym: Symbol): Bind =
1983+
typeBindings.getOrElseUpdate(sym, {
1984+
val bindingBounds = TypeBounds.apply(defn.NothingType, defn.AnyType) // TODO recover bounds
1985+
val bsym = ctx.newPatternBoundSymbol((sym.name + "$").toTypeName, bindingBounds, quoted.span)
1986+
Bind(bsym, untpd.Ident(nme.WILDCARD).withType(bindingBounds)).withSpan(quoted.span)
1987+
})
19821988
def replaceTypeBindings = new TypeMap {
19831989
def apply(tp: Type): Type = tp match {
19841990
case tp: TypeRef if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_patternBindHoleAnnot) =>
1985-
val bindingBounds = TypeBounds.apply(defn.NothingType, defn.AnyType) // TODO recover bounds
1986-
val sym = ctx.newPatternBoundSymbol((tp.name + "$").toTypeName, bindingBounds, quoted.span)
1987-
val bind = typeBindings.getOrElseUpdate(tp.typeSymbol,
1988-
Bind(sym, untpd.Ident(nme.WILDCARD).withType(bindingBounds)).withSpan(quoted.span))
1989-
bind.symbol.typeRef
1991+
getBinding(tp.typeSymbol).symbol.typeRef
19901992
case _ => mapOver(tp)
19911993
}
19921994
}
@@ -2001,18 +2003,8 @@ class Typer extends Namer
20012003
try patternHole(tree)
20022004
finally {
20032005
val patType = pat.tpe.widen
2004-
val patType1 = replaceTypeBindings(patType.underlyingIfRepeated(isJava = false))
2006+
val patType1 = patType.underlyingIfRepeated(isJava = false)
20052007
val pat1 = if (patType eq patType1) pat else pat.withType(patType1)
2006-
println("=-=-=-============-=-=-=----=-=-=")
2007-
println(pat)
2008-
println(pat.symbol)
2009-
println(pat.symbol.info)
2010-
println()
2011-
println(pat1)
2012-
println(pat1.symbol)
2013-
println(pat1.symbol.info)
2014-
println()
2015-
println()
20162008
patBuf += pat1
20172009
}
20182010
case ddef: ValOrDefDef =>
@@ -2033,12 +2025,21 @@ class Typer extends Namer
20332025
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(bindingExprTpe)).withSpan(ddef.span)
20342026
}
20352027
super.transform(tree)
2028+
case tdef: TypeDef if tdef.symbol.hasAnnotation(defn.InternalQuoted_patternBindHoleAnnot) =>
2029+
val bindingType = getBinding(tdef.symbol).symbol.typeRef
2030+
val bindingTypeTpe = AppliedType(defn.QuotedTypeType, bindingType :: Nil)
2031+
assert(tdef.name.startsWith("$"))
2032+
val bindName = tdef.name.toString.stripPrefix("$").toTermName
2033+
val sym = ctx0.newPatternBoundSymbol(bindName, bindingTypeTpe, tdef.span)
2034+
patBuf += Bind(sym, untpd.Ident(nme.WILDCARD).withType(bindingTypeTpe)).withSpan(tdef.span)
2035+
super.transform(tree)
20362036
case _ =>
20372037
super.transform(tree)
20382038
}
20392039
}
20402040
val result = splitter.transform(quoted)
2041-
(typeBindings.toList.map(_._2), result, splitter.patBuf.toList)
2041+
val patterns = splitter.patBuf.toList
2042+
(typeBindings.toList.map(_._2), result, patterns)
20422043
}
20432044

20442045
/** A hole the shape pattern of a quoted.Matcher.unapply, representing a splice */

tests/pos/quotedPatterns.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ object Test {
3131
// val a: quoted.matching.Bind[[T] => T => Int] = ff
3232
// z
3333
// case '{ poly[$t]($x); 2 } => ???
34-
case '{ type $T; val x: $T = $a; val y: $T = x; 1 } => ???
34+
// case '{ val x: $t = $a; val y: `$t` = x; 1 } => ???
35+
case '{ type $t; val x: $t = $a; val y: $t = x; 1 } => ???
36+
// case '{ type $t; val x: $t = $a; val y: $t = x; 1 } => ???
3537
case _ => '{1}
3638
}
3739

0 commit comments

Comments
 (0)