diff options
Diffstat (limited to 'test')
37 files changed, 680 insertions, 33 deletions
diff --git a/test/files/instrumented/indy-symbol-literal.scala b/test/files/instrumented/indy-symbol-literal.scala new file mode 100644 index 0000000000..a1c333cf95 --- /dev/null +++ b/test/files/instrumented/indy-symbol-literal.scala @@ -0,0 +1,19 @@ +import scala.tools.partest.instrumented._ +import scala.tools.partest.instrumented.Instrumentation._ + +object Test { + def main(args: Array[String]): Unit = { + 'warmup + startProfiling() + var i = 0; + while (i < 2) { + 'foo.name + i += 1 + } + stopProfiling() + // Only expect a single call to lookup the interned Symbol at each call site the defines + // a single literal. + val Symbol_apply = MethodCallTrace("scala/Symbol$", "apply", "(Ljava/lang/String;)Lscala/Symbol;") + assert(getStatistics.get(Symbol_apply) == Some(1), getStatistics); + } +} diff --git a/test/files/jvm/future-spec/FutureTests.scala b/test/files/jvm/future-spec/FutureTests.scala index abcf1b4cbc..d0de2f5542 100644 --- a/test/files/jvm/future-spec/FutureTests.scala +++ b/test/files/jvm/future-spec/FutureTests.scala @@ -238,7 +238,7 @@ class FutureTests extends MinimalScalaTest { "support pattern matching within a for-comprehension" in { case class Req[T](req: T) case class Res[T](res: T) - def async[T](req: Req[T]) = req match { + def async[T](req: Req[T]) = (req: @unchecked) match { case Req(s: String) => Future { Res(s.length) } case Req(i: Int) => Future { Res((i * 2).toString) } } diff --git a/test/files/jvm/innerClassEnclMethodJavaReflection.scala b/test/files/jvm/innerClassEnclMethodJavaReflection.scala index a4d64d0b67..a60b5cac8e 100644 --- a/test/files/jvm/innerClassEnclMethodJavaReflection.scala +++ b/test/files/jvm/innerClassEnclMethodJavaReflection.scala @@ -25,12 +25,13 @@ object Test extends App { def testClasses(jarOrDirectory: String): Unit = { val classPath = AbstractFile.getDirectory(new java.io.File(jarOrDirectory)) + val basePath = classPath.path + "/" - def flatten(f: AbstractFile): Iterator[AbstractFile] = - if (f.isClassContainer) f.iterator.flatMap(flatten) - else Iterator(f) + def flatten(f: AbstractFile, s: String): Iterator[(AbstractFile, String)] = + if (f.isClassContainer) f.iterator.map(ch => (ch, (if(s.isEmpty) "" else s + "/") + ch.name)).flatMap((flatten _).tupled) + else Iterator((f, s)) - val classFullNames = flatten(classPath).filter(_.hasExtension("class")).map(_.path.replace("/", ".").replaceAll(".class$", "")) + val classFullNames = flatten(classPath, "").filter(_._1.hasExtension("class")).map(_._2.replace("/", ".").replaceAll(".class$", "")) // it seems that Class objects can only be GC'd together with their class loader // (http://stackoverflow.com/questions/2433261/when-and-how-are-classes-garbage-collected-in-java) diff --git a/test/files/neg/compile-time-only-a.check b/test/files/neg/compile-time-only-a.check index b1ed1d24c2..a10f8b6489 100644 --- a/test/files/neg/compile-time-only-a.check +++ b/test/files/neg/compile-time-only-a.check @@ -13,9 +13,15 @@ compile-time-only-a.scala:36: error: C2 compile-time-only-a.scala:38: error: C3 new C3(2) ^ +compile-time-only-a.scala:39: error: C3 + C3(2) + ^ compile-time-only-a.scala:41: error: C4 new C4(2) ^ +compile-time-only-a.scala:42: error: C4 + C4(2) + ^ compile-time-only-a.scala:45: error: C5 2.ext ^ @@ -73,4 +79,4 @@ compile-time-only-a.scala:75: error: placebo compile-time-only-a.scala:75: error: placebo @placebo def x = (2: @placebo) ^ -25 errors found +27 errors found diff --git a/test/files/neg/override-object-no.check b/test/files/neg/override-object-no.check index 9cfda80fc3..972a719b3b 100644 --- a/test/files/neg/override-object-no.check +++ b/test/files/neg/override-object-no.check @@ -20,4 +20,12 @@ an overriding object must conform to the overridden object's class bound; required: case2.Bar[Traversable[String]] override object A extends Bar[List[String]] // err ^ -four errors found +override-object-no.scala:52: error: overriding method x in trait A of type => SI9574.Foo.type; + method x has incompatible type + trait B extends A { def x: Bar.type } // should not compile (SI-9574) + ^ +override-object-no.scala:53: error: overriding method x in trait A of type => SI9574.Foo.type; + object x has incompatible type + trait C extends A { override object x } + ^ +6 errors found diff --git a/test/files/neg/override-object-no.scala b/test/files/neg/override-object-no.scala index 745cdb2332..517408886d 100644 --- a/test/files/neg/override-object-no.scala +++ b/test/files/neg/override-object-no.scala @@ -43,3 +43,14 @@ package case2 { override object A extends Bar[List[String]] // err } } + +// Both overridden and overriding members must be objects, not vals with a module type +object SI9574 { + object Foo + object Bar + trait A { def x: Foo.type } + trait B extends A { def x: Bar.type } // should not compile (SI-9574) + trait C extends A { override object x } + trait D { object x; def y = x } + trait E extends D { override val x: super.x.type = y } // OK but doesn't need object subtyping exception +} diff --git a/test/files/neg/t8685.check b/test/files/neg/t8685.check new file mode 100644 index 0000000000..1780a20b6e --- /dev/null +++ b/test/files/neg/t8685.check @@ -0,0 +1,45 @@ +t8685.scala:6: warning: constructor D in class D is deprecated: ctor D is depr +case class D @deprecated("ctor D is depr", since="now") (i: Int) + ^ +t8685.scala:35: warning: class C is deprecated: class C is depr + def f = C(42) + ^ +t8685.scala:37: warning: object E is deprecated: module E is depr + def h = E(42) + ^ +t8685.scala:37: warning: class E is deprecated: class E is depr + def h = E(42) + ^ +t8685.scala:38: warning: object F is deprecated: module F is depr + def i = F.G(42) + ^ +t8685.scala:39: warning: object F in object Extra is deprecated: Extra module F is depr + def j = Extra.F.G(42) + ^ +t8685.scala:43: warning: value gg in trait Applies is deprecated: member gg + def k = this.gg.H(0) + ^ +t8685.scala:45: warning: class K in object J is deprecated: Inner K is depr + def l = J.K(42) + ^ +t8685.scala:48: warning: class C is deprecated: class C is depr + def f = new C(42) + ^ +t8685.scala:49: warning: constructor D in class D is deprecated: ctor D is depr + def g = new D(42) + ^ +t8685.scala:50: warning: class E is deprecated: class E is depr + def h = new E(42) + ^ +t8685.scala:51: warning: object F is deprecated: module F is depr + def i = new F.G(42) + ^ +t8685.scala:52: warning: object F in object Extra is deprecated: Extra module F is depr + def j = new Extra.F.G(42) + ^ +t8685.scala:53: warning: class K in object J is deprecated: Inner K is depr + def l = new J.K(42) + ^ +error: No warnings can be incurred under -Xfatal-warnings. +14 warnings found +one error found diff --git a/test/files/neg/t8685.flags b/test/files/neg/t8685.flags new file mode 100644 index 0000000000..c6bfaf1f64 --- /dev/null +++ b/test/files/neg/t8685.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/test/files/neg/t8685.scala b/test/files/neg/t8685.scala new file mode 100644 index 0000000000..711680ecbd --- /dev/null +++ b/test/files/neg/t8685.scala @@ -0,0 +1,54 @@ + + +@deprecated("class C is depr", since="now") +case class C(i: Int) + +case class D @deprecated("ctor D is depr", since="now") (i: Int) + +@deprecated("class E is depr", since="now") +case class E(i: Int) +@deprecated("module E is depr", since="now") +object E + +@deprecated("module F is depr", since="now") +object F { + case class G(i: Int) +} + +object G { + case class H(i: Int) +} + +object Extra { + @deprecated("Extra module F is depr", since="now") + object F { + case class G(i: Int) + } +} + +object J { + @deprecated("Inner K is depr", since="now") + case class K(i: Int) +} + +trait Applies { + def f = C(42) + def g = D(42) + def h = E(42) + def i = F.G(42) + def j = Extra.F.G(42) + + @deprecated("member gg", since="now") + val gg = G + def k = this.gg.H(0) + + def l = J.K(42) +} +trait News { + def f = new C(42) + def g = new D(42) + def h = new E(42) + def i = new F.G(42) + def j = new Extra.F.G(42) + def l = new J.K(42) +} diff --git a/test/files/neg/t9572.check b/test/files/neg/t9572.check new file mode 100644 index 0000000000..b95bd015cf --- /dev/null +++ b/test/files/neg/t9572.check @@ -0,0 +1,7 @@ +t9572.scala:3: error: too many elements for tuple: 23, allowed: 22 + val term23 = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) + ^ +t9572.scala:5: error: too many elements for tuple: 23, allowed: 22 + val type23: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int) = null + ^ +two errors found diff --git a/test/files/neg/t9572.scala b/test/files/neg/t9572.scala new file mode 100644 index 0000000000..32b2db320e --- /dev/null +++ b/test/files/neg/t9572.scala @@ -0,0 +1,6 @@ +class T9572 { + val term22 = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22) + val term23 = (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) + val type22: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int) = null + val type23: (Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int) = null +} diff --git a/test/files/pos/t9542.scala b/test/files/pos/t9542.scala new file mode 100644 index 0000000000..d65f7ac4c6 --- /dev/null +++ b/test/files/pos/t9542.scala @@ -0,0 +1,8 @@ +object O { + trait T + + class VC(val self: Any) extends AnyVal { + def extMethod(f: F1[T, Any]) = () + } +} +trait F1[A, B] diff --git a/test/files/presentation/doc/doc.scala b/test/files/presentation/doc/doc.scala index f2233f1828..ce431910ee 100644 --- a/test/files/presentation/doc/doc.scala +++ b/test/files/presentation/doc/doc.scala @@ -118,6 +118,12 @@ object Test extends InteractiveTest { } } + // The remainder of this test has been found to fail intermittently on Windows + // only. The problem is difficult to isolate and reproduce; see + // https://github.com/scala/scala-dev/issues/72 for details. + // So if we're on Windows, let's just bail out here. + if (scala.util.Properties.isWin) return + // Check inter-classes documentation one-time retrieved ok. val baseSource = findSource("Base.scala") val derivedSource = findSource("Derived.scala") diff --git a/test/files/run/indy-via-macro-with-dynamic-args/Bootstrap.java b/test/files/run/indy-via-macro-with-dynamic-args/Bootstrap.java new file mode 100644 index 0000000000..5c9ce01cf4 --- /dev/null +++ b/test/files/run/indy-via-macro-with-dynamic-args/Bootstrap.java @@ -0,0 +1,17 @@ +package test; + +import java.lang.invoke.*; +import java.util.regex.Pattern; + +public final class Bootstrap { + private Bootstrap() { + } + + /** Pre-compile a regex */ + public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, + MethodType invokedType, + String value) throws Throwable { + MethodHandle Pattern_matcher = MethodHandles.lookup().findVirtual(java.util.regex.Pattern.class, "matcher", MethodType.fromMethodDescriptorString("(Ljava/lang/CharSequence;)Ljava/util/regex/Matcher;", lookup.lookupClass().getClassLoader())); + return new ConstantCallSite(Pattern_matcher.bindTo(Pattern.compile(value))); + } +} diff --git a/test/files/run/indy-via-macro-with-dynamic-args/Test_2.scala b/test/files/run/indy-via-macro-with-dynamic-args/Test_2.scala new file mode 100644 index 0000000000..77c2b522c7 --- /dev/null +++ b/test/files/run/indy-via-macro-with-dynamic-args/Test_2.scala @@ -0,0 +1,6 @@ +object Test { + def main(args: Array[String]) { + val s = "foo!bar" + assert(Macro.matcher("foo.bar", s).matches == true) + } +} diff --git a/test/files/run/indy-via-macro-with-dynamic-args/macro_1.scala b/test/files/run/indy-via-macro-with-dynamic-args/macro_1.scala new file mode 100644 index 0000000000..cb8719a235 --- /dev/null +++ b/test/files/run/indy-via-macro-with-dynamic-args/macro_1.scala @@ -0,0 +1,33 @@ +import java.util.regex._ + +import scala.reflect.internal.SymbolTable +import scala.reflect.macros.blackbox._ +import language.experimental.macros + +object Macro { + /** + * Equivalent to Pattern.compile(pat).matcher(text), but caches the compiled regex (using invokedynamic) if + * `pat` is a literal. + */ + def matcher(pat: String, text: CharSequence): Matcher = macro Macro.impl + def impl(c: Context)(pat: c.Tree, text: c.Tree): c.Tree = { + def Indy(bootstrapMethod: c.Symbol, bootstrapArgs: List[c.universe.Literal], dynArgs: List[c.Tree]): c.Tree = { + val symtab = c.universe.asInstanceOf[SymbolTable] + import symtab._ + val paramSym = NoSymbol.newTermSymbol(TermName("x")).setInfo(typeOf[CharSequence]) + val dummySymbol = NoSymbol.newTermSymbol(TermName("matcher")).setInfo(internal.methodType(paramSym :: Nil, typeOf[java.util.regex.Matcher])) + val bootstrapArgTrees: List[Tree] = Literal(Constant(bootstrapMethod)).setType(NoType) :: bootstrapArgs.asInstanceOf[List[Tree]] + val result = ApplyDynamic(Ident(dummySymbol).setType(dummySymbol.info), bootstrapArgTrees ::: dynArgs.asInstanceOf[List[Tree]]) + result.setType(dummySymbol.info.resultType) + result.asInstanceOf[c.Tree] + } + import c.universe._ + pat match { + case l @ Literal(Constant(pat: String)) => + val boostrapSym = typeOf[test.Bootstrap].companion.member(TermName("bootstrap")) + Indy(boostrapSym, l :: Nil, text :: Nil) + case _ => + q"_root_.java.util.regex.Pattern.compile($pat).matcher($text)" + } + } +} diff --git a/test/files/run/indy-via-macro/Bootstrap.java b/test/files/run/indy-via-macro/Bootstrap.java new file mode 100644 index 0000000000..af4f5dfd4f --- /dev/null +++ b/test/files/run/indy-via-macro/Bootstrap.java @@ -0,0 +1,16 @@ +package test; + +import java.lang.invoke.*; +import java.util.regex.Pattern; + +public final class Bootstrap { + private Bootstrap() { + } + + /** Pre-compile a regex */ + public static CallSite bootstrap(MethodHandles.Lookup lookup, String invokedName, + MethodType invokedType, + String value) throws Throwable { + return new ConstantCallSite(MethodHandles.constant(Pattern.class, Pattern.compile(value))); + } +} diff --git a/test/files/run/indy-via-macro/Test_2.scala b/test/files/run/indy-via-macro/Test_2.scala new file mode 100644 index 0000000000..830947a46b --- /dev/null +++ b/test/files/run/indy-via-macro/Test_2.scala @@ -0,0 +1,5 @@ +object Test { + def main(args: Array[String]) { + assert(Macro.compilePattern("foo.bar").matcher("foo!bar").matches) + } +}
\ No newline at end of file diff --git a/test/files/run/indy-via-macro/macro_1.scala b/test/files/run/indy-via-macro/macro_1.scala new file mode 100644 index 0000000000..66e319e262 --- /dev/null +++ b/test/files/run/indy-via-macro/macro_1.scala @@ -0,0 +1,32 @@ +import java.util.regex.Pattern + +import scala.reflect.internal.SymbolTable +import scala.reflect.macros.blackbox._ +import language.experimental.macros + +object Macro { + /** + * Equivalent to Pattern.compile(s), but caches the compiled regex (using invokedynamic) if + * `s` is a literal. + */ + def compilePattern(s: String): Pattern = macro Macro.impl + def impl(c: Context)(s: c.Tree): c.Tree = { + def Indy(bootstrapMethod: c.Symbol, bootstrapArgs: List[c.universe.Literal]): c.Tree = { + val symtab = c.universe.asInstanceOf[SymbolTable] + import symtab._ + val dummySymbol = NoSymbol.newTermSymbol(TermName("compile")).setInfo(NullaryMethodType(typeOf[Pattern])) + val args: List[Tree] = Literal(Constant(bootstrapMethod)).setType(NoType) :: bootstrapArgs.asInstanceOf[List[Tree]] + val result = ApplyDynamic(Ident(dummySymbol).setType(dummySymbol.info), args) + result.setType(dummySymbol.info.resultType) + result.asInstanceOf[c.Tree] + } + import c.universe._ + s match { + case l @ Literal(Constant(s: String)) => + val boostrapSym = typeOf[test.Bootstrap].companion.member(TermName("bootstrap")) + Indy(boostrapSym, l :: Nil) + case _ => + q"_root_.java.util.regex.Pattern.compile($s)" + } + } +} diff --git a/test/files/run/numbereq.scala b/test/files/run/numbereq.scala index 7ce4b23cf8..1f12d0643e 100644 --- a/test/files/run/numbereq.scala +++ b/test/files/run/numbereq.scala @@ -1,6 +1,7 @@ object Test { def mkNumbers(x: Int): List[AnyRef] = { - val base = List( + //Use explicit AnyRef to workaround known limitation of type inference with F-Bounds + val base = List[AnyRef]( BigDecimal(x), BigInt(x), new java.lang.Double(x.toDouble), diff --git a/test/files/run/t7974.check b/test/files/run/t7974.check index 4eae5eb152..f649161ae9 100644 --- a/test/files/run/t7974.check +++ b/test/files/run/t7974.check @@ -1,26 +1,12 @@ - // access flags 0x9 - public static <clinit>()V - GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; - LDC "Symbolic1" - INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; - PUTSTATIC Symbols.symbol$1 : Lscala/Symbol; - GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; - LDC "Symbolic2" - INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; - PUTSTATIC Symbols.symbol$2 : Lscala/Symbol; - GETSTATIC scala/Symbol$.MODULE$ : Lscala/Symbol$; - LDC "Symbolic3" - INVOKEVIRTUAL scala/Symbol$.apply (Ljava/lang/String;)Lscala/Symbol; - PUTSTATIC Symbols.symbol$3 : Lscala/Symbol; - RETURN - MAXSTACK = 2 - MAXLOCALS = 0 - - // access flags 0x1 public someSymbol1()Lscala/Symbol; - GETSTATIC Symbols.symbol$1 : Lscala/Symbol; + INVOKEDYNAMIC apply()Lscala/Symbol; [ + // handle kind 0x6 : INVOKESTATIC + scala/runtime/SymbolLiteral.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; + // arguments: + "Symbolic1" + ] ARETURN MAXSTACK = 1 MAXLOCALS = 1 @@ -28,7 +14,12 @@ // access flags 0x1 public someSymbol2()Lscala/Symbol; - GETSTATIC Symbols.symbol$2 : Lscala/Symbol; + INVOKEDYNAMIC apply()Lscala/Symbol; [ + // handle kind 0x6 : INVOKESTATIC + scala/runtime/SymbolLiteral.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; + // arguments: + "Symbolic2" + ] ARETURN MAXSTACK = 1 MAXLOCALS = 1 @@ -36,7 +27,12 @@ // access flags 0x1 public sameSymbol1()Lscala/Symbol; - GETSTATIC Symbols.symbol$1 : Lscala/Symbol; + INVOKEDYNAMIC apply()Lscala/Symbol; [ + // handle kind 0x6 : INVOKESTATIC + scala/runtime/SymbolLiteral.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; + // arguments: + "Symbolic1" + ] ARETURN MAXSTACK = 1 MAXLOCALS = 1 @@ -56,7 +52,12 @@ ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V ALOAD 0 - GETSTATIC Symbols.symbol$3 : Lscala/Symbol; + INVOKEDYNAMIC apply()Lscala/Symbol; [ + // handle kind 0x6 : INVOKESTATIC + scala/runtime/SymbolLiteral.bootstrap(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/String;)Ljava/lang/invoke/CallSite; + // arguments: + "Symbolic3" + ] PUTFIELD Symbols.someSymbol3 : Lscala/Symbol; RETURN MAXSTACK = 2 diff --git a/test/files/run/t9349/data.scala b/test/files/run/t9349/data.scala new file mode 100644 index 0000000000..f88a6cfaeb --- /dev/null +++ b/test/files/run/t9349/data.scala @@ -0,0 +1 @@ +case class Outer(i: Int) { class Inner } diff --git a/test/files/run/t9349/test.scala b/test/files/run/t9349/test.scala new file mode 100644 index 0000000000..ebce4e77dd --- /dev/null +++ b/test/files/run/t9349/test.scala @@ -0,0 +1,21 @@ +object Test { + def main(args: Array[String]): Unit = { + val o1 = Outer(5) + o1 match { + case o @ Outer(_) => + val i = new o.Inner + } + o1 match { + case o : Outer => + val i = new o.Inner + + } + object Extractor { + def unapply(a: Any): Option[Outer] = Some(o1) + } + null match { + case Extractor(o2) => + val i = new o2.Inner + } + } +} diff --git a/test/files/run/t9567.scala b/test/files/run/t9567.scala new file mode 100644 index 0000000000..69896b8650 --- /dev/null +++ b/test/files/run/t9567.scala @@ -0,0 +1,18 @@ +object Test { + def testMethodLocalCaseClass { + case class MethodLocalWide( + f01: Int, f02: Int, f03: Int, f04: Int, f05: Int, f06: Int, f07: Int, f08: Int, f09: Int, f10: Int, + f11: Int, f12: Int, f13: Int, f14: Int, f15: Int, f16: Int, f17: Int, f18: Int, f19: Int, f20: Int, + f21: Int, f22: Int, f23: Int) + + val instance = MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + val result = instance match { + case MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) => true + case _ => false + } + assert(result) + } + def main(args: Array[String]) { + testMethodLocalCaseClass + } +} diff --git a/test/files/run/t9567b.scala b/test/files/run/t9567b.scala new file mode 100644 index 0000000000..88cef0a60e --- /dev/null +++ b/test/files/run/t9567b.scala @@ -0,0 +1,19 @@ +object Test { + def testMethodLocalCaseClass { + object MethodLocalWide + case class MethodLocalWide( + f01: Int, f02: Int, f03: Int, f04: Int, f05: Int, f06: Int, f07: Int, f08: Int, f09: Int, f10: Int, + f11: Int, f12: Int, f13: Int, f14: Int, f15: Int, f16: Int, f17: Int, f18: Int, f19: Int, f20: Int, + f21: Int, f22: Int, f23: Int) + + val instance = MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + val result = instance match { + case MethodLocalWide(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) => true + case _ => false + } + assert(result) + } + def main(args: Array[String]) { + testMethodLocalCaseClass + } +} diff --git a/test/files/run/t9567c.scala b/test/files/run/t9567c.scala new file mode 100644 index 0000000000..560bea8821 --- /dev/null +++ b/test/files/run/t9567c.scala @@ -0,0 +1,29 @@ +case class CaseSequenceTopLevel(as: Int*) + +object Test { + def main(args: Array[String]): Unit = { + + val buffer1 = collection.mutable.Buffer(0, 0) + CaseSequenceTopLevel(buffer1: _*) match { + case CaseSequenceTopLevel(_, i) => + buffer1(1) = 1 + assert(i == 0, i) // fails in 2.11.7 -optimize + } + + case class CaseSequence(as: Int*) + val buffer2 = collection.mutable.Buffer(0, 0) + CaseSequence(buffer2: _*) match { + case CaseSequence(_, i) => + buffer2(1) = 1 + assert(i == 0, i) + } + + case class CaseSequenceWithVar(var x: Any, as: Int*) + val buffer3 = collection.mutable.Buffer(0, 0) + CaseSequenceWithVar("", buffer3: _*) match { + case CaseSequenceWithVar(_, _, i) => // crashes in 2.11.7 + buffer2(1) = 1 + assert(i == 0, i) + } + } +} diff --git a/test/junit/scala/collection/IteratorTest.scala b/test/junit/scala/collection/IteratorTest.scala index b0639ef365..4df29e36c0 100644 --- a/test/junit/scala/collection/IteratorTest.scala +++ b/test/junit/scala/collection/IteratorTest.scala @@ -186,4 +186,32 @@ class IteratorTest { assertEquals(1, y.next) assertFalse(x.hasNext) // was true, after advancing underlying iterator } + // SI-9623 + @Test def noExcessiveHasNextInJoinIterator: Unit = { + var counter = 0 + val exp = List(1,2,3,1,2,3) + def it: Iterator[Int] = new Iterator[Int] { + val parent = List(1,2,3).iterator + def next(): Int = parent.next + def hasNext: Boolean = { counter += 1; parent.hasNext } + } + // Iterate separately + val res = new mutable.ArrayBuffer[Int] + it.foreach(res += _) + it.foreach(res += _) + assertSameElements(exp, res) + assertEquals(8, counter) + // JoinIterator + counter = 0 + res.clear + (it ++ it).foreach(res += _) + assertSameElements(exp, res) + assertEquals(8, counter) // was 17 + // ConcatIterator + counter = 0 + res.clear + (Iterator.empty ++ it ++ it).foreach(res += _) + assertSameElements(exp, res) + assertEquals(8, counter) // was 14 + } } diff --git a/test/junit/scala/collection/SearchingTest.scala b/test/junit/scala/collection/SearchingTest.scala new file mode 100644 index 0000000000..2f939d625e --- /dev/null +++ b/test/junit/scala/collection/SearchingTest.scala @@ -0,0 +1,48 @@ +package scala.collection + +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Assert._ +import org.junit.Test +import scala.collection.Searching._ + +@RunWith(classOf[JUnit4]) +class SearchingTest { + + @Test + def doesLinearSearchOnLinearSeqs() { + + class TestSeq[A](list: List[A]) extends SeqLike[A, TestSeq[A]] { + var elementsAccessed = Set.empty[Int] + + protected[this] def newBuilder = ??? // not needed for this test + def seq = list + def iterator = list.iterator + def length = list.length + def apply(idx: Int) = { elementsAccessed += idx; list(idx) } + } + + val coll = new TestSeq((0 to 6).toList) + + assertEquals(Found(5), coll.search(5)) + assertEquals(Set.empty, coll.elementsAccessed) // linear search should not access elements via apply() + } + + @Test + def doesBinarySearchOnIndexedSeqs() { + + class TestIndexedSeq[A](vec: Vector[A]) extends IndexedSeqLike[A, TestIndexedSeq[A]] { + var elementsAccessed = Set.empty[Int] + + protected[this] def newBuilder = ??? // not needed for this test + def seq = vec + def length = vec.length + def apply(idx: Int) = { elementsAccessed += idx; vec(idx) } + } + + val coll = new TestIndexedSeq((0 to 6).toVector) + + assertEquals(Found(5), coll.search(5)) + assertEquals(Set(3, 5), coll.elementsAccessed) + } +} diff --git a/test/junit/scala/collection/immutable/VectorTest.scala b/test/junit/scala/collection/immutable/VectorTest.scala new file mode 100644 index 0000000000..69f74872d0 --- /dev/null +++ b/test/junit/scala/collection/immutable/VectorTest.scala @@ -0,0 +1,30 @@ +package scala.collection.immutable + +import org.junit.Assert._ +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 +import org.junit.Test + +@RunWith(classOf[JUnit4]) +class VectorTest { + + @Test + def hasCorrectDropAndTakeMethods() { + val v = Vector(0) ++ Vector(1 to 64: _*) + + assertEquals(Vector(0, 1), v take 2) + assertEquals(Vector(63, 64), v takeRight 2) + assertEquals(Vector(2 to 64: _*), v drop 2) + assertEquals(Vector(0 to 62: _*), v dropRight 2) + + assertEquals(v, v take Int.MaxValue) + assertEquals(v, v takeRight Int.MaxValue) + assertEquals(Vector.empty[Int], v drop Int.MaxValue) + assertEquals(Vector.empty[Int], v dropRight Int.MaxValue) + + assertEquals(Vector.empty[Int], v take Int.MinValue) + assertEquals(Vector.empty[Int], v takeRight Int.MinValue) + assertEquals(v, v drop Int.MinValue) + assertEquals(v, v dropRight Int.MinValue) + } +} diff --git a/test/junit/scala/math/BigDecimalTest.scala b/test/junit/scala/math/BigDecimalTest.scala index a9e2481f37..5de02cbe0c 100644 --- a/test/junit/scala/math/BigDecimalTest.scala +++ b/test/junit/scala/math/BigDecimalTest.scala @@ -260,4 +260,9 @@ class BigDecimalTest { testPrecision() testRounded() } + + @Test + def testIsComparable() { + assert(BigDecimal(0.1).isInstanceOf[java.lang.Comparable[_]]) + } } diff --git a/test/junit/scala/math/BigIntTest.scala b/test/junit/scala/math/BigIntTest.scala new file mode 100644 index 0000000000..5a5694a775 --- /dev/null +++ b/test/junit/scala/math/BigIntTest.scala @@ -0,0 +1,16 @@ +package scala.math + +import java.math.{BigInteger => BI, MathContext => MC} + +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(classOf[JUnit4]) +class BigIntTest { + + @Test + def testIsComparable() { + assert(BigInt(1).isInstanceOf[java.lang.Comparable[_]]) + } +} diff --git a/test/junit/scala/reflect/ClassTagTest.scala b/test/junit/scala/reflect/ClassTagTest.scala index 90cc981fc1..49022dccda 100644 --- a/test/junit/scala/reflect/ClassTagTest.scala +++ b/test/junit/scala/reflect/ClassTagTest.scala @@ -26,4 +26,14 @@ class ClassTagTest { @Test def checkDouble = assertTrue(checkNotInt[Double] (0.toDouble)) @Test def checkBoolean = assertTrue(checkNotInt[Boolean](false)) @Test def checkUnit = assertTrue(checkNotInt[Unit] ({})) -}
\ No newline at end of file + + @Test def t9534: Unit = { + val ct = implicitly[scala.reflect.ClassTag[Unit]] + val a1 = ct.newArray(1) + a1(0) = () + val a2 = ct.wrap.newArray(1) + a2(0) = a1 + val a3 = ct.newArray2(1) + a3(0) = a1 + } +} diff --git a/test/junit/scala/reflect/internal/TypesTest.scala b/test/junit/scala/reflect/internal/TypesTest.scala index 95194ef0a4..05a77cfb47 100644 --- a/test/junit/scala/reflect/internal/TypesTest.scala +++ b/test/junit/scala/reflect/internal/TypesTest.scala @@ -1,9 +1,10 @@ package scala.reflect.internal import org.junit.Assert._ -import org.junit.Test +import org.junit.{Assert, Test} import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import scala.collection.mutable import scala.tools.nsc.symtab.SymbolTableForUnitTesting @RunWith(classOf[JUnit4]) @@ -32,4 +33,29 @@ class TypesTest { val uniquelyNarrowed2 = refinedType(boolWithString1narrow2 :: Nil, NoSymbol) assert(uniquelyNarrowed1 =:= uniquelyNarrowed2) } + + @Test + def testTransitivityWithModuleTypeRef(): Unit = { + import rootMirror.EmptyPackageClass + val (module, moduleClass) = EmptyPackageClass.newModuleAndClassSymbol(TermName("O"), NoPosition, 0L) + val minfo = ClassInfoType(List(ObjectTpe), newScope, moduleClass) + module.moduleClass setInfo minfo + module setInfo module.moduleClass.tpe + val tp1 = TypeRef(ThisType(EmptyPackageClass), moduleClass, Nil) + val tp2 = SingleType(ThisType(EmptyPackageClass), module) + val tp3 = ThisType(moduleClass) + val tps = List(tp1, tp2, tp3) + val results = mutable.Buffer[String]() + tps.permutations.foreach { + case ts @ List(a, b, c) => + def tsShownRaw = ts.map(t => showRaw(t)).mkString(", ") + if (a <:< b && b <:< c && !(a <:< c)) results += s"<:< intransitive: $tsShownRaw" + if (a =:= b && b =:= c && !(a =:= c)) results += s"=:= intransitive: $tsShownRaw" + } + results.toList match { + case Nil => // okay + case xs => + Assert.fail(xs.mkString("\n")) + } + } } diff --git a/test/scaladoc/run/SI-9620.check b/test/scaladoc/run/SI-9620.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/SI-9620.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/SI-9620.scala b/test/scaladoc/run/SI-9620.scala new file mode 100644 index 0000000000..96260aad9a --- /dev/null +++ b/test/scaladoc/run/SI-9620.scala @@ -0,0 +1,43 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + override def code = """ + package a + + trait Foo[S] { + def foo(t: S): Int = 123 + } + + /** Boo with only one foo method, hopefully! + * @hideImplicitConversion BooShouldNotAppearIsFoo + */ + trait Boo[T] + + object Boo { + sealed trait ShouldNotAppear + implicit class BooShouldNotAppearIsFoo(boo: Boo[ShouldNotAppear]) extends Foo[ShouldNotAppear] + implicit class BooLongIsFoo(boo: Boo[Long]) extends Foo[Long] + } + """ + + // no need for special settings + def scaladocSettings = "-implicits" + + def testModel(rootPackage: Package) = { + import access._ + + // Assert Boo only has one implicit conversion + val boo = rootPackage._package("a")._trait("Boo") + val conversions = boo._conversions("a.Boo.BooShouldNotAppearIsFoo") ++ boo._conversions("a.Boo.BooLongIsFoo") + assert(conversions.length == 1, conversions.length + " == 1") + + // Assert that the implicit conversion is not "BooShouldNotAppearIsFoo" + assert(conversions.head.conversionShortName == "BooLongIsFoo", + conversions.head.conversionShortName + " == BooLongIsFoo") + + // Assert that the same for full path + assert(conversions.head.conversionQualifiedName == "a.Boo.BooLongIsFoo", + conversions.head.conversionQualifiedName + " == a.Boo.BooLongIsFoo") + } +} diff --git a/test/scaladoc/run/tag-requirements.check b/test/scaladoc/run/tag-requirements.check new file mode 100644 index 0000000000..184273b883 --- /dev/null +++ b/test/scaladoc/run/tag-requirements.check @@ -0,0 +1,16 @@ +newSource:3: warning: Only one '@version' tag is allowed + /** + ^ +newSource:9: warning: Tag '@param' must be followed by a symbol name + /** + ^ +newSource:9: warning: Tag '@param' is not recognised + /** + ^ +newSource:14: warning: Only one '@param' tag for symbol b is allowed + /** + ^ +newSource:20: warning: Tag '@unrecognised' is not recognised + /** + ^ +Done. diff --git a/test/scaladoc/run/tag-requirements.scala b/test/scaladoc/run/tag-requirements.scala new file mode 100644 index 0000000000..24f1fab761 --- /dev/null +++ b/test/scaladoc/run/tag-requirements.scala @@ -0,0 +1,53 @@ +import scala.tools.nsc.doc.base._ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest + +object Test extends ScaladocModelTest { + + override def code = + """ + package scala.test.scaladoc.tagrequirements + /** + * object comment + * @version 1.0 + * @version 2.0 + */ + object Test { + /** + * foo comment + * @param + */ + def foo(b: Any) = ??? + /** + * bar comment + * @param b A value + * @param b A value + */ + def bar(b: Any) = ??? + /** + * baz comment + * @unrecognised + */ + def baz() = ??? + } + """ + + def scaladocSettings = "" + + def testModel(root: Package) = { + // get the quick access implicit defs in scope (_package(s), _class(es), _trait(s), object(s) _method(s), _value(s)) + import access._ + + val base = root._package("scala")._package("test")._package("scaladoc")._package("tagrequirements") + + val test = base._object("Test") + /* + * We only care about the warnings which are side effects but we assert on the comment to + * avoid static code analysis noise about unused values. + */ + assert(extractCommentText(test.comment.get) == "object comment") + assert(extractCommentText(test._method("foo").comment.get) == "foo comment") + assert(extractCommentText(test._method("bar").comment.get) == "bar comment") + assert(extractCommentText(test._method("baz").comment.get) == "baz comment") + } +} |