diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-01-29 09:59:54 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-01-29 09:59:54 +1000 |
commit | 1db62995b52b06f5037331172b3f54739d720d62 (patch) | |
tree | 0b684c4adfcb800fa195947b37fdb5dc89731552 /test/files | |
parent | 8b5f2b435b4b14089806406c8923f7e845d10ef6 (diff) | |
parent | eb15950e697eb77e52733f81c65e2d51951ad881 (diff) | |
download | scala-1db62995b52b06f5037331172b3f54739d720d62.tar.gz scala-1db62995b52b06f5037331172b3f54739d720d62.tar.bz2 scala-1db62995b52b06f5037331172b3f54739d720d62.zip |
Merge commit 'eb15950' into merge/2.11.x-to-2.12.x-20150129
Diffstat (limited to 'test/files')
71 files changed, 675 insertions, 37 deletions
diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 2dad608451..bbf5e9b528 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -12,7 +12,7 @@ It would fail on the following inputs: (Kult(_), Kult(_)), (Qult(), Qult()) ^ patmatexhaust.scala:49: warning: match may not be exhaustive. It would fail on the following inputs: Gp(), Gu - def ma4(x:Deep) = x match { // missing cases: Gu, Gp + def ma4(x:Deep) = x match { // missing cases: Gu, Gp which is not abstract so must be included ^ patmatexhaust.scala:55: warning: unreachable code case _ if 1 == 0 => diff --git a/test/files/neg/patmatexhaust.flags b/test/files/neg/patmatexhaust.flags index 85d8eb2ba2..3b01ca062c 100644 --- a/test/files/neg/patmatexhaust.flags +++ b/test/files/neg/patmatexhaust.flags @@ -1 +1 @@ --Xfatal-warnings +-Xfatal-warnings -Ypatmat-exhaust-depth off
\ No newline at end of file diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala index f937197829..26f0c12a91 100644 --- a/test/files/neg/patmatexhaust.scala +++ b/test/files/neg/patmatexhaust.scala @@ -46,7 +46,7 @@ class TestSealedExhaustive { // compile only case _ => } - def ma4(x:Deep) = x match { // missing cases: Gu, Gp + def ma4(x:Deep) = x match { // missing cases: Gu, Gp which is not abstract so must be included case Ga => } diff --git a/test/files/neg/t3240.check b/test/files/neg/t3240.check deleted file mode 100644 index efae682c66..0000000000 --- a/test/files/neg/t3240.check +++ /dev/null @@ -1,4 +0,0 @@ -t3240.scala:3: error: only classes can have declared but undefined members - type t - ^ -one error found diff --git a/test/files/neg/t6902.scala b/test/files/neg/t6902.scala index ce5ff8b6fb..627c324279 100644 --- a/test/files/neg/t6902.scala +++ b/test/files/neg/t6902.scala @@ -16,7 +16,7 @@ object Test { // at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50) // at scala.tools.nsc.Global.abort(Global.scala:249) // at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850) - ((1: Byte): @unchecked @annotation.switch) match { + ((1: Byte): @unchecked) match { case 1 => 2 case 1 => 3 // crash } diff --git a/test/files/neg/t8217-local-alias-requires-rhs.check b/test/files/neg/t8217-local-alias-requires-rhs.check new file mode 100644 index 0000000000..0d4f0864ba --- /dev/null +++ b/test/files/neg/t8217-local-alias-requires-rhs.check @@ -0,0 +1,10 @@ +t8217-local-alias-requires-rhs.scala:6: error: only classes can have declared but undefined members + type B + ^ +t8217-local-alias-requires-rhs.scala:3: error: only classes can have declared but undefined members + type A + ^ +t8217-local-alias-requires-rhs.scala:14: error: only classes can have declared but undefined members + def this(a: Any) = { this(); type C } + ^ +three errors found diff --git a/test/files/neg/t8217-local-alias-requires-rhs.scala b/test/files/neg/t8217-local-alias-requires-rhs.scala new file mode 100644 index 0000000000..12b7976835 --- /dev/null +++ b/test/files/neg/t8217-local-alias-requires-rhs.scala @@ -0,0 +1,15 @@ +trait Alias { + def foo = { + type A + } + val bar = { + type B + object O { + type OK + } + } +} + +class C { + def this(a: Any) = { this(); type C } +} diff --git a/test/files/neg/t8291.check b/test/files/neg/t8291.check new file mode 100644 index 0000000000..c9972e5575 --- /dev/null +++ b/test/files/neg/t8291.check @@ -0,0 +1,7 @@ +t8291.scala:5: error: Could not find implicit for Int or String + implicitly[X[Int, String]] + ^ +t8291.scala:6: error: Could not find implicit for Int or String + implicitly[Z[String]] + ^ +two errors found diff --git a/test/files/neg/t8291.scala b/test/files/neg/t8291.scala new file mode 100644 index 0000000000..b344586a56 --- /dev/null +++ b/test/files/neg/t8291.scala @@ -0,0 +1,7 @@ +@scala.annotation.implicitNotFound("Could not find implicit for ${T} or ${U}") trait X[T, U] + +object Test { + type Z[U] = X[Int, U] + implicitly[X[Int, String]] + implicitly[Z[String]] +} diff --git a/test/files/neg/t8430.check b/test/files/neg/t8430.check index 7c6a73ce53..dbc0c70bba 100644 --- a/test/files/neg/t8430.check +++ b/test/files/neg/t8430.check @@ -1,25 +1,25 @@ t8430.scala:15: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ t8430.scala:16: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ t8430.scala:17: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ t8430.scala:18: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ t8430.scala:19: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ t8430.scala:20: warning: match may not be exhaustive. -It would fail on the following inputs: ??, LetC, LetF, LetL(IntLit), LetP +It would fail on the following inputs: LetC, LetF, LetL(BooleanLit), LetL(IntLit), LetL(UnitLit), LetP (tree: Tree) => tree match {case LetL(CharLit) => ??? } ^ error: No warnings can be incurred under -Xfatal-warnings. diff --git a/test/files/neg/t8430.flags b/test/files/neg/t8430.flags index 85d8eb2ba2..6f60189a8d 100644 --- a/test/files/neg/t8430.flags +++ b/test/files/neg/t8430.flags @@ -1 +1 @@ --Xfatal-warnings +-Xfatal-warnings -Ypatmat-exhaust-depth off diff --git a/test/files/neg/t845.check b/test/files/neg/t845.check deleted file mode 100644 index 07ed7e417b..0000000000 --- a/test/files/neg/t845.check +++ /dev/null @@ -1,4 +0,0 @@ -t845.scala:4: error: only classes can have declared but undefined members - type Bar; - ^ -one error found diff --git a/test/files/neg/t8731.check b/test/files/neg/t8731.check new file mode 100644 index 0000000000..2a9af475fc --- /dev/null +++ b/test/files/neg/t8731.check @@ -0,0 +1,9 @@ +t8731.scala:5: warning: matches with two cases or fewer are emitted using if-then-else instead of switch + def f(x: Int) = (x: @annotation.switch) match { + ^ +t8731.scala:10: warning: could not emit switch for @switch annotated match + def g(x: Int) = (x: @annotation.switch) match { + ^ +error: No warnings can be incurred under -Xfatal-warnings. +two warnings found +one error found diff --git a/test/files/neg/t8731.flags b/test/files/neg/t8731.flags new file mode 100644 index 0000000000..e8fb65d50c --- /dev/null +++ b/test/files/neg/t8731.flags @@ -0,0 +1 @@ +-Xfatal-warnings
\ No newline at end of file diff --git a/test/files/neg/t8731.scala b/test/files/neg/t8731.scala new file mode 100644 index 0000000000..d93fe706ad --- /dev/null +++ b/test/files/neg/t8731.scala @@ -0,0 +1,15 @@ +class C { + // not a compile-time constant due to return type + final val K: Int = 20 + + def f(x: Int) = (x: @annotation.switch) match { + case K => 0 + case 2 => 1 + } + + def g(x: Int) = (x: @annotation.switch) match { + case K => 0 + case 2 => 1 + case 3 => 2 + } +} diff --git a/test/files/neg/t8869.check b/test/files/neg/t8869.check new file mode 100644 index 0000000000..40b8570f9f --- /dev/null +++ b/test/files/neg/t8869.check @@ -0,0 +1,7 @@ +t8869.scala:5: error: class Option takes type parameters + def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported! + ^ +t8869.scala:7: error: class Option takes type parameters + type l2[x] = Option // error correctly reported + ^ +two errors found diff --git a/test/files/neg/t8869.scala b/test/files/neg/t8869.scala new file mode 100644 index 0000000000..0c7f0c9451 --- /dev/null +++ b/test/files/neg/t8869.scala @@ -0,0 +1,10 @@ +class TC[T[_]] { + def identity[A](a: T[A]): T[A] = a +} +object Test { + def value: TC[({type l1[x] = Option})#l1] = ??? // error not reported! + + type l2[x] = Option // error correctly reported + def value1: TC[l2] = ??? +} + diff --git a/test/files/neg/t8890.check b/test/files/neg/t8890.check new file mode 100644 index 0000000000..1b69d6cf30 --- /dev/null +++ b/test/files/neg/t8890.check @@ -0,0 +1,4 @@ +t8890.scala:6: error: not found: type Str + def bar(x: Str): Unit = ??? + ^ +one error found diff --git a/test/files/neg/t8890.scala b/test/files/neg/t8890.scala new file mode 100644 index 0000000000..cbdeb11d43 --- /dev/null +++ b/test/files/neg/t8890.scala @@ -0,0 +1,11 @@ +package foo + +class A { + /** The other */ + def bar(x: Int): Unit = ??? + def bar(x: Str): Unit = ??? +} + +class B { + (new A).bar(0) +}
\ No newline at end of file diff --git a/test/files/pos/switch-small.flags b/test/files/pos/switch-small.flags deleted file mode 100644 index 85d8eb2ba2..0000000000 --- a/test/files/pos/switch-small.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings diff --git a/test/files/pos/switch-small.scala b/test/files/pos/switch-small.scala deleted file mode 100644 index 9de9ca028e..0000000000 --- a/test/files/pos/switch-small.scala +++ /dev/null @@ -1,8 +0,0 @@ -import annotation._ - -object Test { - def f(x: Int) = (x: @switch) match { - case 1 => 1 - case _ => 2 - } -} diff --git a/test/files/neg/t3240.scala b/test/files/pos/t3240.scala index cf197a406d..cf197a406d 100644 --- a/test/files/neg/t3240.scala +++ b/test/files/pos/t3240.scala diff --git a/test/files/pos/t8267.scala b/test/files/pos/t8267.scala new file mode 100644 index 0000000000..37b498fe3e --- /dev/null +++ b/test/files/pos/t8267.scala @@ -0,0 +1,33 @@ +class Bippy { trait Foo[A] } + +final class RichBippy[C <: Bippy with Singleton](val c1: C) { + def f: Int = 1 + def f[A](x: A)(ev: c1.Foo[A]): Int = 2 + + def g[A <: Nothing](x: A): Int = 1 + def g[A](x: A)(ev: c1.Foo[A]): Int = 2 + + def h[A](x: A)(ev: c1.Foo[A]): Int = 1 + + def i(x: Nothing): Int = 1 + def i(x: AnyRef)(ev: c1.Foo[x.type]): Int = 2 +} + +object p { + + val c = new Bippy + val d0 = new RichBippy[c.type](c) + def d1 = new RichBippy[c.type](c) + + d0.f[Int](5)(null: c.Foo[Int]) // ok + d1.f[Int](5)(null: c.Foo[Int]) // fails + + d0.g[Int](5)(null: c.Foo[Int]) // ok + d1.g[Int](5)(null: c.Foo[Int]) // fails + + d0.h[Int](5)(null: c.Foo[Int]) // ok + d1.h[Int](5)(null: c.Foo[Int]) // ok + + d0.i("")(null) // ok + d1.i("")(null) // ok +} diff --git a/test/files/neg/t845.scala b/test/files/pos/t845.scala index ddf6a16f32..ddf6a16f32 100644 --- a/test/files/neg/t845.scala +++ b/test/files/pos/t845.scala diff --git a/test/files/pos/t8868a/Sub_2.scala b/test/files/pos/t8868a/Sub_2.scala new file mode 100644 index 0000000000..a19b529c88 --- /dev/null +++ b/test/files/pos/t8868a/Sub_2.scala @@ -0,0 +1 @@ +class Sub extends T diff --git a/test/files/pos/t8868a/T_1.scala b/test/files/pos/t8868a/T_1.scala new file mode 100644 index 0000000000..9fb97b1413 --- /dev/null +++ b/test/files/pos/t8868a/T_1.scala @@ -0,0 +1,6 @@ +class C + +trait T { + @deprecated(since = "", message = "") + class X +} diff --git a/test/files/pos/t8868b/Sub_2.scala b/test/files/pos/t8868b/Sub_2.scala new file mode 100644 index 0000000000..58b44db2b3 --- /dev/null +++ b/test/files/pos/t8868b/Sub_2.scala @@ -0,0 +1,2 @@ +class Sub extends T + diff --git a/test/files/pos/t8868b/T_1.scala b/test/files/pos/t8868b/T_1.scala new file mode 100644 index 0000000000..0b71cfdaa3 --- /dev/null +++ b/test/files/pos/t8868b/T_1.scala @@ -0,0 +1,4 @@ +@deprecated(since = "2.4.0", message = "") +trait T { + class X +} diff --git a/test/files/pos/t8868c/Sub_2.scala b/test/files/pos/t8868c/Sub_2.scala new file mode 100644 index 0000000000..58b44db2b3 --- /dev/null +++ b/test/files/pos/t8868c/Sub_2.scala @@ -0,0 +1,2 @@ +class Sub extends T + diff --git a/test/files/pos/t8868c/T_1.scala b/test/files/pos/t8868c/T_1.scala new file mode 100644 index 0000000000..dc541950d8 --- /dev/null +++ b/test/files/pos/t8868c/T_1.scala @@ -0,0 +1,9 @@ +class C(a: Any) extends annotation.StaticAnnotation + +@C({val x = 0; x}) +trait T { + class X + + @C({val x = 0; x}) + def foo = 42 +} diff --git a/test/files/pos/t8894.scala b/test/files/pos/t8894.scala new file mode 100644 index 0000000000..3b26f1ae7e --- /dev/null +++ b/test/files/pos/t8894.scala @@ -0,0 +1,12 @@ +class CC(val i: Int, val s: String) +object CC extends { + type P = (Int, String) + + //def unapply(c: CC): Option[(Int, String)] = Some((c.i, c.s)) // OK + def unapply(c: CC): Option[P] = Some((c.i, c.s)) // fails (because of the type alias) +} + +class Test { + val cc = new CC(23, "foo") + val CC(i, s) = cc +}
\ No newline at end of file diff --git a/test/files/presentation/doc.check b/test/files/presentation/doc.check new file mode 100644 index 0000000000..5a3ff13151 --- /dev/null +++ b/test/files/presentation/doc.check @@ -0,0 +1 @@ +reload: Base.scala, Class.scala, Derived.scala diff --git a/test/files/presentation/doc/doc.scala b/test/files/presentation/doc/doc.scala new file mode 100755 index 0000000000..f2233f1828 --- /dev/null +++ b/test/files/presentation/doc/doc.scala @@ -0,0 +1,147 @@ +import scala.reflect.internal.util.{ BatchSourceFile, SourceFile } +import scala.tools.nsc.doc +import scala.tools.nsc.doc.base._ +import scala.tools.nsc.doc.base.comment._ +import scala.tools.nsc.interactive._ +import scala.tools.nsc.interactive.tests._ + +object Test extends InteractiveTest { + val tags = Seq( + "@example `\"abb\".permutations = Iterator(abb, bab, bba)`", + "@version 1.0, 09/07/2012", + "@since 2.10", + "@todo this is unsafe!", + "@note Don't inherit!", + "@see something else" + ) + + val names = Seq("Class", "Def", "Val", "Var", "AbstracType", "TypeAlias", "Trait", "InnerClass") + val bareText = + """abstract class %s { + | def %s = "" + | val %s = "" + | var %s: String = _ + | type %s + | type %s = String + | class %s + |} + |trait %s""".stripMargin.format(names: _*) + + def docComment(nTags: Int) = "/**\n%s*/".format(tags.take(nTags).mkString("\n")) + + def text(name: String, nTags: Int) = { + val nameIndex = bareText.indexOf(name) + val (pre, post) = bareText.splitAt(nameIndex) + val crIndex = pre.lastIndexOf("\n") + val (prepre, prepost) = pre.splitAt(crIndex) + prepre + docComment(nTags) + prepost + post + } + + override lazy val compiler = { + prepareSettings(settings) + new Global(settings, compilerReporter) with MemberLookupBase with CommentFactoryBase with doc.ScaladocGlobalTrait { + outer => + + val global: this.type = this + + override lazy val analyzer = new { + val global: outer.type = outer + } with doc.ScaladocAnalyzer with InteractiveAnalyzer { + override def newTyper(context: Context): InteractiveTyper with ScaladocTyper = + new Typer(context) with InteractiveTyper with ScaladocTyper + } + + def chooseLink(links: List[LinkTo]): LinkTo = links.head + def internalLink(sym: Symbol, site: Symbol) = None + def toString(link: LinkTo) = link.toString + def warnNoLink = false + def findExternalLink(sym: Symbol, name: String) = None + + override def forScaladoc = true + + def getComment(sym: Symbol, source: SourceFile, fragments: List[(Symbol,SourceFile)]): Option[Comment] = { + val docResponse = new Response[(String, String, Position)] + askDocComment(sym, source, sym.owner, fragments, docResponse) + docResponse.get.left.toOption flatMap { + case (expanded, raw, pos) => + if (expanded.isEmpty) + None + else + Some(ask { () => parseAtSymbol(expanded, raw, pos, sym.owner) }) + } + } + } + } + + override def runDefaultTests() { + import compiler._ + def findSource(name: String) = sourceFiles.find(_.file.name == name).get + + val className = names.head + for (name <- names; + i <- 1 to tags.length) { + val newText = text(name, i) + val source = findSource("Class.scala") + val batch = new BatchSourceFile(source.file, newText.toCharArray) + val reloadResponse = new Response[Unit] + compiler.askReload(List(batch), reloadResponse) + reloadResponse.get.left.toOption match { + case None => + println("Couldn't reload") + case Some(_) => + val parseResponse = new Response[Tree] + askParsedEntered(batch, true, parseResponse) + parseResponse.get.left.toOption match { + case None => + println("Couldn't parse") + case Some(_) => + val sym = compiler.ask { () => + val toplevel = compiler.rootMirror.EmptyPackage.info.decl(TypeName(name)) + if (toplevel eq NoSymbol) { + val clazz = compiler.rootMirror.EmptyPackage.info.decl(TypeName(className)) + val term = clazz.info.decl(TermName(name)) + if (term eq NoSymbol) clazz.info.decl(TypeName(name)) else + if (term.isAccessor) term.accessed else term + } else toplevel + } + + getComment(sym, batch, (sym,batch)::Nil) match { + case None => println(s"Got no doc comment for $name") + case Some(comment) => + import comment._ + def cnt(bodies: Iterable[Body]) = bodies.size + val actual = cnt(example) + cnt(version) + cnt(since) + cnt(todo) + cnt(note) + cnt(see) + if (actual != i) + println(s"Got docComment with $actual tags instead of $i, file text:\n$newText") + } + } + } + } + + // Check inter-classes documentation one-time retrieved ok. + val baseSource = findSource("Base.scala") + val derivedSource = findSource("Derived.scala") + def existsText(where: Any, text: String): Boolean = where match { + case s: String => s contains text + case s: Seq[_] => s exists (existsText(_, text)) + case p: Product => p.productIterator exists (existsText(_, text)) + case c: Comment => existsText(c.body, text) + } + val (derived, base) = compiler.ask { () => + val derived = compiler.rootMirror.RootPackage.info.decl(newTermName("p")).info.decl(newTypeName("Derived")) + (derived, derived.ancestors(0)) + } + val cmt1 = getComment(derived, derivedSource, (base, baseSource)::(derived, derivedSource)::Nil) + if (!existsText(cmt1, "This is Derived comment")) + println("Unexpected Derived class comment:"+cmt1) + + val (fooDerived, fooBase) = compiler.ask { () => + val decl = derived.tpe.decl(newTermName("foo")) + (decl, decl.allOverriddenSymbols(0)) + } + + val cmt2 = getComment(fooDerived, derivedSource, (fooBase, baseSource)::(fooDerived, derivedSource)::Nil) + if (!existsText(cmt2, "Base method has documentation")) + println("Unexpected foo method comment:"+cmt2) + } +} diff --git a/test/files/presentation/doc/src/Class.scala b/test/files/presentation/doc/src/Class.scala new file mode 100755 index 0000000000..a974bd6f5c --- /dev/null +++ b/test/files/presentation/doc/src/Class.scala @@ -0,0 +1 @@ +object Class
\ No newline at end of file diff --git a/test/files/presentation/doc/src/p/Base.scala b/test/files/presentation/doc/src/p/Base.scala new file mode 100755 index 0000000000..d91632b6f6 --- /dev/null +++ b/test/files/presentation/doc/src/p/Base.scala @@ -0,0 +1,11 @@ +package p + +/** + * @define BaseComment This is $BaseVar comment. + */ +trait Base { + /** + * Base method has documentation. + */ + def foo: String +} diff --git a/test/files/presentation/doc/src/p/Derived.scala b/test/files/presentation/doc/src/p/Derived.scala new file mode 100755 index 0000000000..1a9c9a26d1 --- /dev/null +++ b/test/files/presentation/doc/src/p/Derived.scala @@ -0,0 +1,9 @@ +package p + +/** + * $BaseComment + * @define BaseVar Derived + */ +class Derived extends Base { + def foo = "" +} diff --git a/test/files/run/t4594-repl-settings.scala b/test/files/run/t4594-repl-settings.scala index 4202991607..db5dc19866 100644 --- a/test/files/run/t4594-repl-settings.scala +++ b/test/files/run/t4594-repl-settings.scala @@ -14,7 +14,7 @@ object Test extends SessionTest { |warning: there was one deprecation warning; re-run with -deprecation for details |a: String | - |scala> :settings +deprecation + |scala> :settings -deprecation | |scala> def b = depp |<console>:8: warning: method depp is deprecated: Please don't do that. diff --git a/test/files/run/t4788-separate-compilation.check b/test/files/run/t4788-separate-compilation.check new file mode 100644 index 0000000000..172ad90102 --- /dev/null +++ b/test/files/run/t4788-separate-compilation.check @@ -0,0 +1,5 @@ +Some(@Ljava/lang/Deprecated;()) +None +None +Some(@LCAnnotation;() // invisible) +Some(@LRAnnotation;()) diff --git a/test/files/run/t4788-separate-compilation/CAnnotation_1.java b/test/files/run/t4788-separate-compilation/CAnnotation_1.java new file mode 100644 index 0000000000..7120218d62 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/CAnnotation_1.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Retention(value=CLASS) +@interface CAnnotation {} diff --git a/test/files/run/t4788-separate-compilation/C_1.scala b/test/files/run/t4788-separate-compilation/C_1.scala new file mode 100644 index 0000000000..aba9b595e4 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/C_1.scala @@ -0,0 +1,2 @@ +@CAnnotation +class C diff --git a/test/files/run/t4788-separate-compilation/D_1.scala b/test/files/run/t4788-separate-compilation/D_1.scala new file mode 100644 index 0000000000..c2479fba86 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/D_1.scala @@ -0,0 +1,5 @@ +@Deprecated +class DJava + +@deprecated("", "") +class DScala diff --git a/test/files/run/t4788-separate-compilation/RAnnotation_1.java b/test/files/run/t4788-separate-compilation/RAnnotation_1.java new file mode 100644 index 0000000000..f24cf66f7b --- /dev/null +++ b/test/files/run/t4788-separate-compilation/RAnnotation_1.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention(value=RUNTIME) +@interface RAnnotation {} diff --git a/test/files/run/t4788-separate-compilation/R_1.scala b/test/files/run/t4788-separate-compilation/R_1.scala new file mode 100644 index 0000000000..ab0cd065d9 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/R_1.scala @@ -0,0 +1,2 @@ +@RAnnotation +class R diff --git a/test/files/run/t4788-separate-compilation/SAnnotation_1.java b/test/files/run/t4788-separate-compilation/SAnnotation_1.java new file mode 100644 index 0000000000..471f27d82a --- /dev/null +++ b/test/files/run/t4788-separate-compilation/SAnnotation_1.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +@Retention(value=SOURCE) +@interface SAnnotation {} diff --git a/test/files/run/t4788-separate-compilation/S_1.scala b/test/files/run/t4788-separate-compilation/S_1.scala new file mode 100644 index 0000000000..f8756d9bc8 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/S_1.scala @@ -0,0 +1,2 @@ +@SAnnotation +class S diff --git a/test/files/run/t4788-separate-compilation/Test_2.scala b/test/files/run/t4788-separate-compilation/Test_2.scala new file mode 100644 index 0000000000..cbbb5ff386 --- /dev/null +++ b/test/files/run/t4788-separate-compilation/Test_2.scala @@ -0,0 +1,35 @@ +import java.io.PrintWriter; + +import scala.tools.partest.BytecodeTest +import scala.tools.asm.util._ +import scala.tools.nsc.util.stringFromWriter + +object Test extends BytecodeTest { + def annotationsForClass(className: String): Option[String] = { + val classNode = loadClassNode(className, skipDebugInfo = false) + val textifier = new Textifier + classNode.accept(new TraceClassVisitor(null, textifier, null)) + + val classString = stringFromWriter(w => textifier.print(w)) + classString + .split('\n') + .filterNot(_.contains("@Lscala/reflect/ScalaSignature")) + .find(_.contains("@L")) + .map(_.trim) + } + + def show { + // It seems like @java.lang.Deprecated shows up in both the + // Deprecated attribute and RuntimeVisibleAnnotation attribute, + // while @scala.deprecated only shows up in the Deprecated attribute. + // The check file just documents status quo, not sure if Scala + // should brought in line with Java or not... + // See the commit message and SI-8883 for more info. + println(annotationsForClass("DJava")) + println(annotationsForClass("DScala")) + + println(annotationsForClass("S")) + println(annotationsForClass("C")) + println(annotationsForClass("R")) + } +} diff --git a/test/files/run/t4788.check b/test/files/run/t4788.check new file mode 100644 index 0000000000..172ad90102 --- /dev/null +++ b/test/files/run/t4788.check @@ -0,0 +1,5 @@ +Some(@Ljava/lang/Deprecated;()) +None +None +Some(@LCAnnotation;() // invisible) +Some(@LRAnnotation;()) diff --git a/test/files/run/t4788/C.scala b/test/files/run/t4788/C.scala new file mode 100644 index 0000000000..aba9b595e4 --- /dev/null +++ b/test/files/run/t4788/C.scala @@ -0,0 +1,2 @@ +@CAnnotation +class C diff --git a/test/files/run/t4788/CAnnotation.java b/test/files/run/t4788/CAnnotation.java new file mode 100644 index 0000000000..7120218d62 --- /dev/null +++ b/test/files/run/t4788/CAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.CLASS; + +@Retention(value=CLASS) +@interface CAnnotation {} diff --git a/test/files/run/t4788/D.scala b/test/files/run/t4788/D.scala new file mode 100644 index 0000000000..c2479fba86 --- /dev/null +++ b/test/files/run/t4788/D.scala @@ -0,0 +1,5 @@ +@Deprecated +class DJava + +@deprecated("", "") +class DScala diff --git a/test/files/run/t4788/R.scala b/test/files/run/t4788/R.scala new file mode 100644 index 0000000000..ab0cd065d9 --- /dev/null +++ b/test/files/run/t4788/R.scala @@ -0,0 +1,2 @@ +@RAnnotation +class R diff --git a/test/files/run/t4788/RAnnotation.java b/test/files/run/t4788/RAnnotation.java new file mode 100644 index 0000000000..f24cf66f7b --- /dev/null +++ b/test/files/run/t4788/RAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention(value=RUNTIME) +@interface RAnnotation {} diff --git a/test/files/run/t4788/S.scala b/test/files/run/t4788/S.scala new file mode 100644 index 0000000000..f8756d9bc8 --- /dev/null +++ b/test/files/run/t4788/S.scala @@ -0,0 +1,2 @@ +@SAnnotation +class S diff --git a/test/files/run/t4788/SAnnotation.java b/test/files/run/t4788/SAnnotation.java new file mode 100644 index 0000000000..471f27d82a --- /dev/null +++ b/test/files/run/t4788/SAnnotation.java @@ -0,0 +1,5 @@ +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +@Retention(value=SOURCE) +@interface SAnnotation {} diff --git a/test/files/run/t4788/Test.scala b/test/files/run/t4788/Test.scala new file mode 100644 index 0000000000..cbbb5ff386 --- /dev/null +++ b/test/files/run/t4788/Test.scala @@ -0,0 +1,35 @@ +import java.io.PrintWriter; + +import scala.tools.partest.BytecodeTest +import scala.tools.asm.util._ +import scala.tools.nsc.util.stringFromWriter + +object Test extends BytecodeTest { + def annotationsForClass(className: String): Option[String] = { + val classNode = loadClassNode(className, skipDebugInfo = false) + val textifier = new Textifier + classNode.accept(new TraceClassVisitor(null, textifier, null)) + + val classString = stringFromWriter(w => textifier.print(w)) + classString + .split('\n') + .filterNot(_.contains("@Lscala/reflect/ScalaSignature")) + .find(_.contains("@L")) + .map(_.trim) + } + + def show { + // It seems like @java.lang.Deprecated shows up in both the + // Deprecated attribute and RuntimeVisibleAnnotation attribute, + // while @scala.deprecated only shows up in the Deprecated attribute. + // The check file just documents status quo, not sure if Scala + // should brought in line with Java or not... + // See the commit message and SI-8883 for more info. + println(annotationsForClass("DJava")) + println(annotationsForClass("DScala")) + + println(annotationsForClass("S")) + println(annotationsForClass("C")) + println(annotationsForClass("R")) + } +} diff --git a/test/files/run/t5830.check b/test/files/run/t5830.check index 675387eb8e..9260854676 100644 --- a/test/files/run/t5830.check +++ b/test/files/run/t5830.check @@ -1,5 +1,6 @@ a with oef a with oef +a with oef a def with oef def diff --git a/test/files/run/t5830.scala b/test/files/run/t5830.scala index 5d808bfa28..03b9c540e0 100644 --- a/test/files/run/t5830.scala +++ b/test/files/run/t5830.scala @@ -1,12 +1,11 @@ import scala.annotation.switch object Test extends App { - // TODO: should not emit a switch - // def noSwitch(ch: Char, eof: Boolean) = (ch: @switch) match { - // case 'a' if eof => println("a with oef") // then branch - // } + def noSwitch(ch: Char, eof: Boolean) = ch match { + case 'a' if eof => println("a with oef") // then branch + } - def onlyThen(ch: Char, eof: Boolean) = (ch: @switch) match { + def onlyThen(ch: Char, eof: Boolean) = ch match { case 'a' if eof => println("a with oef") // then branch case 'c' => } @@ -18,7 +17,7 @@ object Test extends App { case 'c' => } - def defaultUnguarded(ch: Char, eof: Boolean) = (ch: @switch) match { + def defaultUnguarded(ch: Char, eof: Boolean) = ch match { case ' ' if eof => println("spacey oef") case _ => println("default") } @@ -44,7 +43,7 @@ object Test extends App { // case 'c' => // } - // noSwitch('a', true) + noSwitch('a', true) onlyThen('a', true) // 'a with oef' ifThenElse('a', true) // 'a with oef' ifThenElse('a', false) // 'a' diff --git a/test/files/run/t6011c.scala b/test/files/run/t6011c.scala index 0647e3f81a..96a685b9cf 100644 --- a/test/files/run/t6011c.scala +++ b/test/files/run/t6011c.scala @@ -6,7 +6,7 @@ object Test extends App { // at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:50) // at scala.tools.nsc.Global.abort(Global.scala:249) // at scala.tools.nsc.backend.jvm.GenASM$JPlainBuilder$jcode$.emitSWITCH(GenASM.scala:1850) - ((1: Byte): @unchecked @annotation.switch) match { + ((1: Byte): @unchecked) match { case 1 => 2 case 1 => 3 // crash } diff --git a/test/files/run/t6622.check b/test/files/run/t6622.check new file mode 100644 index 0000000000..5d006d88e6 --- /dev/null +++ b/test/files/run/t6622.check @@ -0,0 +1,10 @@ + O1.resultVal isMemberClass = false, null +class A$1 + O1.resultDef isMemberClass = false, public void O1$.resultDef() +class A$2 + C2.resultVal isMemberClass = false, null +class $B$1 + O3.resultDef isMemberClass = false, public void O3$.resultDef() +class C$1 + O4.resultDefDefault isMemberClass = false, public java.lang.Object O4$.resultDefDefault$default$1() +class C$2 diff --git a/test/files/run/t6622.scala b/test/files/run/t6622.scala new file mode 100644 index 0000000000..de8ffa01bf --- /dev/null +++ b/test/files/run/t6622.scala @@ -0,0 +1,50 @@ +import Test.check + +object O1 { + lazy val resultVal = { + class A + check("O1.resultVal", classOf[A]) + } + + def resultDef = { + class A + check("O1.resultDef", classOf[A]) + } +} + +class C2 { + val resultVal = { + val tmp = { + class B + check("C2.resultVal", classOf[B]) + } + } +} + +object O3 { + def resultDef = { + class C + check("O3.resultDef", classOf[C]) + } +} + +object O4 { + def resultDefDefault(a: Any = { + class C + check("O4.resultDefDefault", classOf[C]) + }) = (); +} + + +object Test extends App { + def check(desc: String, clazz: Class[_]) { + println(s" $desc isMemberClass = ${clazz.isMemberClass}, ${clazz.getEnclosingMethod}") + println(reflect.runtime.currentMirror.classSymbol(clazz)) + } + + O1.resultVal + O1.resultDef + new C2().resultVal + O3.resultDef + O4.resultDefDefault() +} diff --git a/test/files/run/t8087.scala b/test/files/run/t8087.scala new file mode 100644 index 0000000000..6047211756 --- /dev/null +++ b/test/files/run/t8087.scala @@ -0,0 +1,12 @@ +trait Foo { + @volatile private[this] var x: String = "" + @volatile private var y: String = "" +} + +class Bar extends Foo + +object Test extends App { + classOf[Bar].getDeclaredFields.foreach(f => { + assert(java.lang.reflect.Modifier.isVolatile(f.getModifiers), f.getName) + }) +} diff --git a/test/files/run/t8445.check b/test/files/run/t8445.check new file mode 100644 index 0000000000..41fd6d3ed1 --- /dev/null +++ b/test/files/run/t8445.check @@ -0,0 +1 @@ +warning: there was one feature warning; re-run with -feature for details diff --git a/test/files/run/t8445.scala b/test/files/run/t8445.scala new file mode 100644 index 0000000000..ed196b62a2 --- /dev/null +++ b/test/files/run/t8445.scala @@ -0,0 +1,11 @@ +object X { + class Y + def y = new Y { + class Z + def z = classOf[Z] + } +} + +object Test extends App { + assert(X.y.z.getEnclosingClass.getName == "X$$anon$1") +} diff --git a/test/files/run/t8843-repl-xlat.scala b/test/files/run/t8843-repl-xlat.scala new file mode 100644 index 0000000000..6426dbe7d4 --- /dev/null +++ b/test/files/run/t8843-repl-xlat.scala @@ -0,0 +1,33 @@ + +import scala.tools.partest.SessionTest + +// Handy hamburger helper for repl resources +object Test extends SessionTest { + def session = +"""Type in expressions to have them evaluated. +Type :help for more information. + +scala> $intp.isettings.unwrapStrings = false +$intp.isettings.unwrapStrings: Boolean = false + +scala> class Bippy +defined class Bippy + +scala> $intp.classLoader getResource "Bippy.class" +res0: java.net.URL = memory:(memory)/$line4/$read$$iw$$iw$Bippy.class + +scala> ($intp.classLoader getResources "Bippy.class").nextElement +res1: java.net.URL = memory:(memory)/$line4/$read$$iw$$iw$Bippy.class + +scala> ($intp.classLoader classBytes "Bippy").nonEmpty +res2: Boolean = true + +scala> ($intp.classLoader classAsStream "Bippy") != null +res3: Boolean = true + +scala> $intp.classLoader getResource "Bippy" +res4: java.net.URL = null + +scala> :quit""" +} + diff --git a/test/files/run/t8845.flags b/test/files/run/t8845.flags new file mode 100644 index 0000000000..aada25f80d --- /dev/null +++ b/test/files/run/t8845.flags @@ -0,0 +1 @@ +-Ybackend:GenBCode -Ynooptimize diff --git a/test/files/run/t8845.scala b/test/files/run/t8845.scala new file mode 100644 index 0000000000..8ccdbdadc7 --- /dev/null +++ b/test/files/run/t8845.scala @@ -0,0 +1,17 @@ +// crashes compiler under GenASM, works under GenBCode. +object Interpreter { + def mkDataProp(i: Int) = i + def break(n: Int): Unit = + try { + n match { + case _ => + val newDesc = mkDataProp(n) + n match { case _ => return } + } + } catch { case e: Throwable => } + finally { } +} + +object Test extends App { + Interpreter.break(0) +} diff --git a/test/files/run/t8888.flags b/test/files/run/t8888.flags new file mode 100644 index 0000000000..48b438ddf8 --- /dev/null +++ b/test/files/run/t8888.flags @@ -0,0 +1 @@ +-Ydelambdafy:method diff --git a/test/files/run/t8888.scala b/test/files/run/t8888.scala new file mode 100644 index 0000000000..36cc1ddf3e --- /dev/null +++ b/test/files/run/t8888.scala @@ -0,0 +1,12 @@ +class C { + final def resume: Unit = (this: Any) match { + case x : C => (x: Any) match { + case y : C => + () => (x, y) // used to trigger a ClassFormatError under -Ydelambdafy:method + } + } +} + +object Test extends App { + new C().resume +} diff --git a/test/files/run/t8907.scala b/test/files/run/t8907.scala new file mode 100644 index 0000000000..7952ac82d9 --- /dev/null +++ b/test/files/run/t8907.scala @@ -0,0 +1,39 @@ +import scala.tools.partest._ +import java.io.File + +object Test extends StoreReporterDirectTest { + def code = ??? + + def compileCode(code: String) = { + val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator") + compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code) + } + + def show(): Unit = { + compileCode(""" + class C { class Inner } + + class D { + object O { + def foo(c: C)(i: c.Inner): c.Inner = ??? + } + } + """) + assert(filteredInfos.isEmpty, filteredInfos) + deleteClass("C") + compileCode(""" + class E { + def foo = { + (null: D).toString + } + } + """) + assert(storeReporter.infos.isEmpty, storeReporter.infos.mkString("\n")) // Included a MissingRequirementError before. + } + + def deleteClass(name: String) { + val classFile = new File(testOutput.path, name + ".class") + assert(classFile.exists) + assert(classFile.delete()) + } +} diff --git a/test/files/run/virtpatmat_nested_lists.flags b/test/files/run/virtpatmat_nested_lists.flags new file mode 100644 index 0000000000..ca9a4c0697 --- /dev/null +++ b/test/files/run/virtpatmat_nested_lists.flags @@ -0,0 +1 @@ +-Ypatmat-exhaust-depth off
\ No newline at end of file diff --git a/test/files/run/virtpatmat_opt_sharing.flags b/test/files/run/virtpatmat_opt_sharing.flags new file mode 100644 index 0000000000..ca9a4c0697 --- /dev/null +++ b/test/files/run/virtpatmat_opt_sharing.flags @@ -0,0 +1 @@ +-Ypatmat-exhaust-depth off
\ No newline at end of file |