@@ -252,28 +252,6 @@ object Erasure extends TypeTestsCasts{
252
252
if (tree.typeOpt.isRef(defn.UnitClass )) tree.withType(tree.typeOpt)
253
253
else super .typedLiteral(tree)
254
254
255
- override def typedIf (tree : untpd.If , pt : Type )(implicit ctx : Context ): If = {
256
- val tree1 = super .typedIf(tree, pt)
257
- if (pt.isValueType) tree1
258
- else cpy.If (tree1)(thenp = adapt(tree1.thenp, tree1.tpe), elsep = adapt(tree1.elsep, tree1.tpe))
259
- }
260
-
261
- override def typedMatch (tree : untpd.Match , pt : Type )(implicit ctx : Context ): Match = {
262
- val tree1 = super .typedMatch(tree, pt).asInstanceOf [Match ]
263
- if (pt.isValueType) tree1
264
- else cpy.Match (tree1)(tree1.selector, tree1.cases.map(adaptCase(_, tree1.tpe)))
265
- }
266
-
267
- override def typedTry (tree : untpd.Try , pt : Type )(implicit ctx : Context ): Try = {
268
- val tree1 = super .typedTry(tree, pt)
269
- if (pt.isValueType) tree1
270
- else cpy.Try (tree1)(expr = adapt(tree1.expr, tree1.tpe), cases = tree1.cases.map(adaptCase(_, tree1.tpe)))
271
- }
272
-
273
- private def adaptCase (cdef : CaseDef , pt : Type )(implicit ctx : Context ): CaseDef =
274
- cpy.CaseDef (cdef)(body = adapt(cdef.body, pt))
275
-
276
-
277
255
/** Type check select nodes, applying the following rewritings exhaustively
278
256
* on selections `e.m`, where `OT` is the type of the owner of `m` and `ET`
279
257
* is the erased type of the selection's original qualifier expression.
@@ -409,9 +387,24 @@ object Erasure extends TypeTestsCasts{
409
387
}
410
388
}
411
389
390
+ // The following four methods take as the proto-type the erasure of the pre-existing type,
391
+ // if the original proto-type is not a value type.
392
+ // This makes all branches be adapted to the correct type.
412
393
override def typedSeqLiteral (tree : untpd.SeqLiteral , pt : Type )(implicit ctx : Context ) =
413
394
super .typedSeqLiteral(tree, erasure(tree.typeOpt))
414
- // proto type of typed seq literal is original type; this makes elements be adapted to correct type.
395
+ // proto type of typed seq literal is original type;
396
+
397
+ override def typedIf (tree : untpd.If , pt : Type )(implicit ctx : Context ) =
398
+ super .typedIf(tree, adaptProto(tree, pt))
399
+
400
+ override def typedMatch (tree : untpd.Match , pt : Type )(implicit ctx : Context ) =
401
+ super .typedMatch(tree, adaptProto(tree, pt))
402
+
403
+ override def typedTry (tree : untpd.Try , pt : Type )(implicit ctx : Context ) =
404
+ super .typedTry(tree, adaptProto(tree, pt))
405
+
406
+ private def adaptProto (tree : untpd.Tree , pt : Type )(implicit ctx : Context ) =
407
+ if (pt.isValueType) pt else erasure(tree.typeOpt)
415
408
416
409
override def typedValDef (vdef : untpd.ValDef , sym : Symbol )(implicit ctx : Context ): ValDef =
417
410
super .typedValDef(untpd.cpy.ValDef (vdef)(
0 commit comments