Fix and test case for #2168.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@18352 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2009-07-20 21:38:13 +00:00
parent 7476e8ee7d
commit c947e72cb6
3 changed files with 10 additions and 1 deletions

View File

@ -114,6 +114,8 @@ trait TreeDSL {
/** Casting & type tests -- working our way toward understanding exactly
* what differs between the different forms of IS and AS.
*
* See ticket #2168 for one illustration of AS vs. AS_ANY.
*/
def AS(tpe: Type) = TypeApply(Select(target, Any_asInstanceOf), List(TypeTree(tpe)))
def AS_ANY(tpe: Type) = gen.mkAsInstanceOf(target, tpe)

View File

@ -988,9 +988,10 @@ trait ParallelMatching extends ast.TreeDSL {
// dig out case field accessors that were buried in (***)
val cfa = if (pats.isCaseHead) casted.accessors else Nil
val caseTemps = srep.tvars match { case x :: xs if x == casted.sym => xs ; case x => x }
def castedScrut = typedValDef(casted.sym, scrut.id AS castedTpe)
def castedScrut = typedValDef(casted.sym, scrut.id AS_ANY castedTpe)
def needCast = if (casted.sym ne scrut.sym) List(castedScrut) else Nil
val vdefs = needCast ::: (
for ((tmp, accessor) <- caseTemps zip cfa) yield
typedValDef(tmp, typer typed fn(casted.id, accessor))

View File

@ -0,0 +1,6 @@
object Test extends Application {
def foo1(x: AnyRef) = x match { case x: Function0[_] => x() }
def foo2(x: AnyRef) = x match { case x: Function0[Any] => x() }
}