scala/scala — pull request #2849 by retronym (2013-08-18 10:46:47+00:00)
Title: SI-7763 Avoid dropping casts in erasure

466b7d29f avoided quadratic complexity in Erasure's treatment
of chained `asInstanceOf` calls. It did so by using the typechecked
qualifier, rather than discarding it.

However, that also dropped the cast altogether! In many cases this
was masked by later inclusion of a cast to the expected type
by `adaptToType`:

at scala.tools.nsc.transform.Erasure$Eraser.cast(Erasure.scala:636)
at scala.tools.nsc.transform.Erasure$Eraser.scala$tools$nsc$transform$Erasure$Eraser$$adaptToType(Erasure.scala:665)
at scala.tools.nsc.transform.Erasure$Eraser.adapt(Erasure.scala:766)
at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5352)

This commit re-wraps the typechecked `qual` in its original
`.asInstanceOf[T]` to preserve semantics while avoiding
the big-O blowup.

Review by @paulp, @magarcia