summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeDSL.scala2
-rw-r--r--src/compiler/scala/tools/nsc/matching/ParallelMatching.scala3
-rw-r--r--test/files/pos/bug2168.scala5
3 files changed, 9 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
index 9c12ac6bd5..97869d5ea5 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeDSL.scala
@@ -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)
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
index 22df6d1bda..cd140e7c49 100644
--- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
+++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala
@@ -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))
diff --git a/test/files/pos/bug2168.scala b/test/files/pos/bug2168.scala
new file mode 100644
index 0000000000..42224236db
--- /dev/null
+++ b/test/files/pos/bug2168.scala
@@ -0,0 +1,5 @@
+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() }
+}
+