Skip to content

Commit 1d138f2

Browse files
committed
A more complete workaround scala#592
1 parent a9ebb46 commit 1d138f2

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TreeTypeMap(
6262

6363
def mapType(tp: Type) =
6464
mapOwnerThis(typeMap(tp).substSym(substFrom, substTo))
65-
65+
6666
private def updateDecls(prevStats: List[Tree], newStats: List[Tree]): Unit =
6767
if (prevStats.isEmpty) assert(newStats.isEmpty)
6868
else {
@@ -77,7 +77,7 @@ class TreeTypeMap(
7777
updateDecls(prevStats.tail, newStats.tail)
7878
}
7979

80-
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = treeMap(tree) match {
80+
override final def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = treeMap(tree) match {
8181
case impl @ Template(constr, parents, self, _) =>
8282
val tmap = withMappedSyms(localSyms(impl :: self :: Nil))
8383
cpy.Template(impl)(

src/dotty/tools/dotc/transform/TypeSpecializer.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,9 @@ class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
180180
transformApply(t)
181181
case t => t
182182
}
183-
184-
new TreeTypeMap(
185-
treeMap = tmap,
186-
typeMap = _
187-
.substDealias(origTParams, instantiations(index))
188-
.subst(origVParams, vparams.flatten.map(_.tpe))
189-
,
190-
oldOwners = tree.symbol :: Nil,
191-
newOwners = newSym :: Nil
192-
) {
193-
// needed to workaround https://github.com/lampepfl/dotty/issues/592
194-
override def transform(t: Tree)(implicit ctx: Context) = super.transform(t) match {
183+
val tp = new TreeMap() {
184+
// needed to workaround https://github.com/lampepfl/dotty/issues/592
185+
override def transform(t: Tree)(implicit ctx: Context) = super.transform(t) match {
195186
case t @ Apply(fun, args) =>
196187
val newArgs = (args zip fun.tpe.firstParamTypes).map{case(t, tpe) => t.ensureConforms(tpe)}
197188
if (sameTypes(args, newArgs)) {
@@ -203,7 +194,20 @@ class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
203194
cpy.DefDef(t)(rhs = t.rhs.ensureConforms(t.tpe.finalResultType))
204195
case t => t
205196
}
206-
}.transform(tree.rhs)
197+
}
198+
199+
val typesReplaced = new TreeTypeMap(
200+
treeMap = tmap,
201+
typeMap = _
202+
.substDealias(origTParams, instantiations(index))
203+
.subst(origVParams, vparams.flatten.map(_.tpe))
204+
,
205+
oldOwners = tree.symbol :: Nil,
206+
newOwners = newSym :: Nil
207+
).transform(tree.rhs)
208+
209+
val expectedTypeFixed = tp.transform(typesReplaced)
210+
expectedTypeFixed.ensureConforms(newSym.info.widen.finalResultType)
207211
}})
208212
}
209213
} else Nil

tests/pos/specialization/this_specialization.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
trait Foo[@specialized +A] {
2-
// all those examples trigger bugs due to https://github.com/lampepfl/dotty/issues/592
2+
// all those examples trigger bugs due to https://github.com/lampepfl/dotty/issues/592
33
def bop[@specialized B >: A]: Foo[B] = new Bar[B](this)
44
def gwa[@specialized B >: A]: Foo[B] = this
55
def gwd[@specialized B >: A]: Foo[B] = {

0 commit comments

Comments
 (0)