summaryrefslogtreecommitdiff
path: root/test/pending/neg
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2009-10-02 17:57:16 +0000
committerMartin Odersky <odersky@gmail.com>2009-10-02 17:57:16 +0000
commit83b67aa805fd1329d6bcc54b1c1fa16416437b6f (patch)
tree3fcc59ba0523f644bceef4676f7a6689f9949417 /test/pending/neg
parent84146e2f53fb1f5e8abbc521121078e932cf82e7 (diff)
downloadscala-83b67aa805fd1329d6bcc54b1c1fa16416437b6f.tar.gz
scala-83b67aa805fd1329d6bcc54b1c1fa16416437b6f.tar.bz2
scala-83b67aa805fd1329d6bcc54b1c1fa16416437b6f.zip
Sequence->Seq
Diffstat (limited to 'test/pending/neg')
-rwxr-xr-xtest/pending/neg/t1545.scala16
-rw-r--r--test/pending/neg/t1800.scala28
-rw-r--r--test/pending/neg/t1845.scala12
-rw-r--r--test/pending/neg/t2080.scala17
-rw-r--r--test/pending/neg/t2180.scala31
5 files changed, 104 insertions, 0 deletions
diff --git a/test/pending/neg/t1545.scala b/test/pending/neg/t1545.scala
new file mode 100755
index 0000000000..d7c0245725
--- /dev/null
+++ b/test/pending/neg/t1545.scala
@@ -0,0 +1,16 @@
+object Main extends Application {
+
+ case class Foo (field : Option[String])
+
+ val x : PartialFunction[Foo,Int] =
+ {
+ c => c.field match {
+ case Some (s) => 42
+ case None => 99
+ }
+ }
+
+ println (x (Foo (None))) // prints 99
+ println (x (Foo (Some ("foo")))) // prints 42
+
+}
diff --git a/test/pending/neg/t1800.scala b/test/pending/neg/t1800.scala
new file mode 100644
index 0000000000..eebbbad9c7
--- /dev/null
+++ b/test/pending/neg/t1800.scala
@@ -0,0 +1,28 @@
+object ObjectHolder {
+ private[ObjectHolder] class PrivateObject
+ def getPrivateObject = new PrivateObject
+}
+
+object Test {
+ def main(args: Array[String]) {
+ // compiler error: class PrivateObject cannot be accessed
+ // in object test.ObjectHolder
+ val a: ObjectHolder.PrivateObject = ObjectHolder.getPrivateObject
+
+ // works fine
+ val b = ObjectHolder.getPrivateObject
+ println(b.getClass)
+ }
+}
+/*
+When declaring objects as private[package/object] or protected[package/object] it is possible to leak out references to these objects into the public api (can be desirable, this in itself is not a problem).
+
+When users of the api receive such private object via a function call, they can create a variable to reference the private object using inferred typing:
+
+val b = getPrivateObject()
+
+However they cannot create such variable using declared typing:
+
+val a: PrivateObject? = getPrivateObject()
+
+The line above will generate a compiler error: "class PrivateObject? cannot be accessed". Which makes sense, because PrivateObject? was declared private. But in this case inferred typing should not work either, otherwise the behaviors of inferred typing and declared typing become inconsistent. */
diff --git a/test/pending/neg/t1845.scala b/test/pending/neg/t1845.scala
new file mode 100644
index 0000000000..cfb28aa03c
--- /dev/null
+++ b/test/pending/neg/t1845.scala
@@ -0,0 +1,12 @@
+// Compiling the attached code makes scalac give a NPE.
+
+import scala.util.parsing.combinator.syntactical.TokenParsers
+import scala.util.parsing.combinator.lexical.StdLexical
+import scala.util.parsing.syntax.StdTokens
+
+class MyTokenParsers extends TokenParsers {
+ import lexical._
+ type Tokens = StdTokens
+ type Elem = lexical.Token
+ val lexical = new StdLexical
+}
diff --git a/test/pending/neg/t2080.scala b/test/pending/neg/t2080.scala
new file mode 100644
index 0000000000..0880a40faa
--- /dev/null
+++ b/test/pending/neg/t2080.scala
@@ -0,0 +1,17 @@
+trait A {
+ type T
+ def f(x : T) : T
+}
+
+trait B extends A {
+ trait T { }
+ override def f(x : T) : T = x
+}
+
+object C extends B {
+ override trait T {
+ def g { }
+ }
+ override def f(x : T) : T = { x.g; x }
+}
+//It compiles without errors, but T in B and T in C are completely unrelated types.
diff --git a/test/pending/neg/t2180.scala b/test/pending/neg/t2180.scala
new file mode 100644
index 0000000000..a8055bf77d
--- /dev/null
+++ b/test/pending/neg/t2180.scala
@@ -0,0 +1,31 @@
+
+
+Given the following code (which is broken):
+
+class Mxml {
+
+ private def processChildren( children:Seq[Any] ):List[Mxml] = {
+
+ children.toList.flatMap ( e => {
+
+ e match {
+
+ case s:scala.collection.Traversable[_] => s case a => List(a)
+
+ }
+
+ })
+
+ }
+
+}
+
+I get the following error:
+
+Mxml.scala:5: error: could not find implicit value for parameter bf:scala.collection.generic.BuilderFactory[Any,List[Mxml],Sequence[Any]].
+
+ children.flatMap ( e => {
+
+I spent 4 hours failing before I figured out the problem. The return type was wrong. It should have been List[Any].
+
+I have seen similar errors with map. My solution in the past has been to change it to a foldLeft because I have never been able to determine how to fix the problem until now.