@@ -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 */
0 commit comments