From 83b67aa805fd1329d6bcc54b1c1fa16416437b6f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 2 Oct 2009 17:57:16 +0000 Subject: Sequence->Seq --- test/pending/neg/t1545.scala | 16 ++++++++++++++++ test/pending/neg/t1800.scala | 28 ++++++++++++++++++++++++++++ test/pending/neg/t1845.scala | 12 ++++++++++++ test/pending/neg/t2080.scala | 17 +++++++++++++++++ test/pending/neg/t2180.scala | 31 +++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100755 test/pending/neg/t1545.scala create mode 100644 test/pending/neg/t1800.scala create mode 100644 test/pending/neg/t1845.scala create mode 100644 test/pending/neg/t2080.scala create mode 100644 test/pending/neg/t2180.scala (limited to 'test/pending/neg') 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. -- cgit v1.2.3