@@ -2,7 +2,6 @@ package dotty.tools.dotc.transform
2
2
3
3
import dotty .tools .dotc .ast .{tpd , TreeTypeMap }
4
4
import dotty .tools .dotc .ast .Trees ._
5
- import dotty .tools .dotc .core .Annotations .Annotation
6
5
import dotty .tools .dotc .core .Contexts .Context
7
6
import dotty .tools .dotc .core .Decorators .StringDecorator
8
7
import dotty .tools .dotc .core .DenotTransformers .InfoTransformer
@@ -13,6 +12,7 @@ import dotty.tools.dotc.core.Types._
13
12
import dotty .tools .dotc .transform .TreeTransforms .{TransformerInfo , MiniPhaseTransform }
14
13
import scala .collection .mutable
15
14
import dotty .tools .dotc .core .StdNames .nme
15
+ import dotty .tools ._
16
16
17
17
class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
18
18
import tpd ._
@@ -175,36 +175,34 @@ class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
175
175
val tmap : (Tree => Tree ) = _ match {
176
176
case Return (t, from) if from.symbol == tree.symbol => Return (t, ref(newSym))
177
177
case t : TypeApply => transformTypeApply(t)
178
- case t : Apply =>
179
- transformApply(t)
178
+ case t : Apply => transformApply(t)
180
179
case t => t
181
180
}
182
- val tp = new TreeMap () {
183
- // needed to workaround https://github.com/lampepfl/dotty/issues/592
184
- override def transform (t : Tree )(implicit ctx : Context ) = super .transform(t) match {
185
- case t @ Apply (fun, args) =>
186
- val newArgs = (args zip fun.tpe.firstParamTypes).map{case (t, tpe) => t.ensureConforms(tpe)}
187
- if (sameTypes(args, newArgs)) {
188
- t
189
- } else tpd.Apply (fun, newArgs)
190
- case t : ValDef =>
191
- cpy.ValDef (t)(rhs = t.rhs.ensureConforms(t.tpe.widen))
192
- case t : DefDef =>
193
- cpy.DefDef (t)(rhs = t.rhs.ensureConforms(t.tpe.finalResultType))
194
- case t => t
195
- }
196
- }
197
181
198
182
val typesReplaced = new TreeTypeMap (
199
183
treeMap = tmap,
200
184
typeMap = _
201
185
.substDealias(origTParams, instantiations(index))
202
- .subst(origVParams, vparams.flatten.map(_.tpe))
203
- ,
186
+ .subst(origVParams, vparams.flatten.map(_.tpe)),
204
187
oldOwners = tree.symbol :: Nil ,
205
188
newOwners = newSym :: Nil
206
189
).transform(tree.rhs)
207
190
191
+ val tp = new TreeMap () {
192
+ // needed to workaround https://github.com/lampepfl/dotty/issues/592
193
+ override def transform (t : Tree )(implicit ctx : Context ) = super .transform(t) match {
194
+ case t @ Apply (fun, args) =>
195
+ assert(sameLength(args, fun.tpe.widen.firstParamTypes))
196
+ val newArgs = (args zip fun.tpe.widen.firstParamTypes).map{case (t, tpe) => t.ensureConforms(tpe)}
197
+ if (sameTypes(args, newArgs)) {
198
+ t
199
+ } else tpd.Apply (fun, newArgs)
200
+ case t : ValDef =>
201
+ cpy.ValDef (t)(rhs = if (t.rhs.isEmpty) EmptyTree else t.rhs.ensureConforms(t.tpt.tpe))
202
+ case t : DefDef =>
203
+ cpy.DefDef (t)(rhs = if (t.rhs.isEmpty) EmptyTree else t.rhs.ensureConforms(t.tpt.tpe))
204
+ case t => t
205
+ }}
208
206
val expectedTypeFixed = tp.transform(typesReplaced)
209
207
expectedTypeFixed.ensureConforms(newSym.info.widen.finalResultType)
210
208
}})
@@ -227,23 +225,13 @@ class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
227
225
val Apply (fun, args) = tree
228
226
fun match {
229
227
case fun : TypeApply => {
230
- println(
231
- s """
232
- |args -> ${args}
233
-
234
- |f.fun -> ${fun.fun.tree}
235
- """ .stripMargin)
236
-
237
228
val newFun = rewireTree(fun)
238
229
if (fun ne newFun) {
239
- val b = (args zip newFun.tpe.firstParamTypes)
240
- val a = b.map{
230
+ val as = (args zip newFun.tpe.widen.firstParamTypes).map{
241
231
case (arg, tpe) =>
242
232
arg.ensureConforms(tpe)
243
233
}
244
- Apply (newFun,a)
245
- /* zip (instantiations zip paramTypes)).map{
246
- case (argType, (specType, castType)) => argType.ensureConforms(specType)})*/
234
+ Apply (newFun,as)
247
235
} else tree
248
236
}
249
237
case _ => tree
0 commit comments