summaryrefslogtreecommitdiff
path: root/test/pending/run/instanceOfAndTypeMatching.scala
diff options
context:
space:
mode:
Diffstat (limited to 'test/pending/run/instanceOfAndTypeMatching.scala')
-rw-r--r--test/pending/run/instanceOfAndTypeMatching.scala58
1 files changed, 29 insertions, 29 deletions
diff --git a/test/pending/run/instanceOfAndTypeMatching.scala b/test/pending/run/instanceOfAndTypeMatching.scala
index 60b11ef0c1..e04ae13585 100644
--- a/test/pending/run/instanceOfAndTypeMatching.scala
+++ b/test/pending/run/instanceOfAndTypeMatching.scala
@@ -6,9 +6,9 @@ object Summary {
class Inner { }
def f() = { class MethodInner ; new MethodInner }
}
-
+
// 1 static issue:
- //
+ //
// Given method in MethodInner: def g(other: MethodInner) = ()
// method1.g(method1) fails to compile with type error.
//
@@ -20,7 +20,7 @@ object Summary {
// traverse a method.
//
// 4 runtime issues:
- //
+ //
// From the outside: inner1.isInstanceOf[outer2.Inner] is true, should (maybe) be false
// From inside inner1: inner2.isInstanceOf[Outer.this.Inner] is true, should (maybe) be false
// From the outside: inner1 match { case _: outer2.Inner => true ... } is true, should definitely be false
@@ -44,13 +44,13 @@ class Outer {
def passInner(other: Inner) = () // pass only Inners from this Outer instance
def passInner2(other: Outer.this.Inner) = () // same as above
def passInnerSharp(other: Outer#Inner) = () // pass any Inner
-
+
def compareSimpleWithTypeMatch(other: Any) = other match {
case _: Inner => true
case _ => false
}
def compareSimpleWithInstanceOf(other: Any) = other.isInstanceOf[Inner]
-
+
def compareSharpWithTypeMatch(other: Any) = {
other match {
case _: Outer#Inner => true
@@ -58,16 +58,16 @@ class Outer {
}
}
def compareSharpWithInstanceOf(other: Any) = other.isInstanceOf[Outer#Inner]
-
+
def comparePathWithTypeMatch(other: Any) = other match {
case _: Outer.this.Inner => true
case _ => false
}
- def comparePathWithInstanceOf(other: Any) = other.isInstanceOf[Outer.this.Inner]
+ def comparePathWithInstanceOf(other: Any) = other.isInstanceOf[Outer.this.Inner]
}
-
+
def f() = {
- class MethodInner {
+ class MethodInner {
def passOuter(other: Outer) = () // pass any Outer
def passThisType(other: Outer.this.type) = () // pass only this Outer instance
def passInner(other: Inner) = () // pass only Inners from this Outer instance
@@ -75,14 +75,14 @@ class Outer {
def passInnerSharp(other: Outer#Inner) = () // pass any Inner
def passMethodInner(other: MethodInner) = () // pass only MethodInners from this Outer instance
// is there any way to refer to Outer#MethodInner? Not that there should be.
-
+
def compareWithInstanceOf(other: Any) = other.isInstanceOf[MethodInner]
def compareWithTypeMatch(other: Any) = other match {
case _: MethodInner => true
case _ => false
}
}
-
+
new MethodInner
}
}
@@ -94,7 +94,7 @@ object Test {
val inner2 = new outer2.Inner
val method1 = outer1.f()
val method2 = outer2.f()
-
+
def testInnerStatic = {
// these should all work
inner1.passOuter(outer1)
@@ -104,7 +104,7 @@ object Test {
inner1.passInner2(inner1)
inner1.passInnerSharp(inner1)
inner1.passInnerSharp(inner2)
-
+
// these should all fail to compile, and do
//
// inner1.passThisType(outer2)
@@ -113,30 +113,30 @@ object Test {
}
def testInnerRuntime = {
println("testInnerRuntime\n")
-
+
List("These should be true under any scenario: ",
- inner1.isInstanceOf[outer1.Inner] ,
+ inner1.isInstanceOf[outer1.Inner] ,
inner1.isInstanceOf[Outer#Inner] ,
(inner1: Any) match { case _: Outer#Inner => true ; case _ => false } ,
(inner1: Any) match { case _: outer1.Inner => true ; case _ => false } ,
inner1.compareSharpWithTypeMatch(inner2) ,
inner1.compareSharpWithInstanceOf(inner2)
) foreach println
-
+
List("These should be true under current proposal: ",
- inner1.compareSimpleWithInstanceOf(inner2)
+ inner1.compareSimpleWithInstanceOf(inner2)
) foreach println
-
+
List("These should be false under current proposal: ",
inner1.compareSimpleWithTypeMatch(inner2) ,
- inner1.comparePathWithTypeMatch(inner2)
+ inner1.comparePathWithTypeMatch(inner2)
) foreach println
-
- List("These return true but I think should return false: ",
+
+ List("These return true but I think should return false: ",
inner1.isInstanceOf[outer2.Inner] , // true
inner1.comparePathWithInstanceOf(inner2) // true
) foreach println
-
+
List("These are doing the wrong thing under current proposal",
(inner1: Any) match { case _: outer2.Inner => true ; case _ => false } // should be false
) foreach println
@@ -159,7 +159,7 @@ object Test {
// method1.passMethodInner(method1)
// ^
method1.passMethodInner(method1)
-
+
// these should all fail to compile, and do
//
// method1.passThisType(outer2)
@@ -167,24 +167,24 @@ object Test {
// method1.passInner2(inner2)
// method1.passMethodInner(method2)
}
-
+
def testMethodInnerRuntime = {
println("\ntestMethodInnerRuntime\n")
-
+
List("These should be true under any scenario: ",
method1.compareWithInstanceOf(method1) ,
- method1.compareWithTypeMatch(method1)
+ method1.compareWithTypeMatch(method1)
) foreach println
-
+
List("These should be true under current proposal: ",
method1.compareWithInstanceOf(method2)
) foreach println
-
+
List("These are doing the wrong thing under current proposal",
method1.compareWithTypeMatch(method2) // should be false
) foreach println
}
-
+
def main(args: Array[String]): Unit = {
testInnerRuntime
testMethodInnerRuntime