diff options
Diffstat (limited to 'test/files')
58 files changed, 617 insertions, 246 deletions
diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index 08372685d6..ce3c8062d7 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -30,7 +30,7 @@ scala> val four: anotherint = 4 four: anotherint = 4 scala> val bogus: anotherint = "hello" -<console>:11: error: type mismatch; +<console>:12: error: type mismatch; found : String("hello") required: anotherint (which expands to) Int @@ -353,7 +353,7 @@ defined class Term scala> def f(e: Exp) = e match { // non-exhaustive warning here case _:Fact => 3 } -<console>:21: warning: match may not be exhaustive. +<console>:22: warning: match may not be exhaustive. It would fail on the following inputs: Exp(), Term() def f(e: Exp) = e match { // non-exhaustive warning here ^ @@ -363,6 +363,6 @@ scala> :quit plusOne: (x: Int)Int res0: Int = 6 res0: String = after reset -<console>:11: error: not found: value plusOne +<console>:12: error: not found: value plusOne plusOne(5) // should be undefined now ^ diff --git a/test/files/neg/implicit-ambiguous-2.check b/test/files/neg/implicit-ambiguous-2.check new file mode 100644 index 0000000000..4a10b0dd65 --- /dev/null +++ b/test/files/neg/implicit-ambiguous-2.check @@ -0,0 +1,4 @@ +implicit-ambiguous-2.scala:10: error: Could not prove Int =!= Int + implicitly[Int =!= Int] + ^ +one error found diff --git a/test/files/neg/implicit-ambiguous-2.scala b/test/files/neg/implicit-ambiguous-2.scala new file mode 100644 index 0000000000..563c8c583f --- /dev/null +++ b/test/files/neg/implicit-ambiguous-2.scala @@ -0,0 +1,11 @@ +object Test { + trait =!=[C, D] + + implicit def neq[E, F] : E =!= F = null + + implicit def neqAmbig1[G, H, J] : J =!= J = null + @annotation.implicitAmbiguous("Could not prove ${I} =!= ${I}") + implicit def neqAmbig2[I] : I =!= I = null + + implicitly[Int =!= Int] +} diff --git a/test/files/neg/implicit-ambiguous-invalid.check b/test/files/neg/implicit-ambiguous-invalid.check new file mode 100644 index 0000000000..68b607c4c2 --- /dev/null +++ b/test/files/neg/implicit-ambiguous-invalid.check @@ -0,0 +1,7 @@ +implicit-ambiguous-invalid.scala:5: warning: Invalid implicitAmbiguous message for method neqAmbig1 in object Test: +The type parameter B referenced in the message of the @implicitAmbiguous annotation is not defined by method neqAmbig1. + implicit def neqAmbig1[A] : A =!= A = null + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/test/files/neg/implicit-ambiguous-invalid.flags b/test/files/neg/implicit-ambiguous-invalid.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/implicit-ambiguous-invalid.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/implicit-ambiguous-invalid.scala b/test/files/neg/implicit-ambiguous-invalid.scala new file mode 100644 index 0000000000..f8f9da655f --- /dev/null +++ b/test/files/neg/implicit-ambiguous-invalid.scala @@ -0,0 +1,6 @@ +object Test { + trait =!=[C, D] + + @annotation.implicitAmbiguous("Could not prove ${A} =!= ${B}") + implicit def neqAmbig1[A] : A =!= A = null +} diff --git a/test/files/neg/implicit-ambiguous.check b/test/files/neg/implicit-ambiguous.check new file mode 100644 index 0000000000..0b3cebcb6f --- /dev/null +++ b/test/files/neg/implicit-ambiguous.check @@ -0,0 +1,4 @@ +implicit-ambiguous.scala:10: error: Could not prove Int =!= Int + implicitly[Int =!= Int] + ^ +one error found diff --git a/test/files/neg/implicit-ambiguous.scala b/test/files/neg/implicit-ambiguous.scala new file mode 100644 index 0000000000..79b1297915 --- /dev/null +++ b/test/files/neg/implicit-ambiguous.scala @@ -0,0 +1,11 @@ +object Test { + trait =!=[C, D] + + implicit def neq[E, F] : E =!= F = null + + @annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}") + implicit def neqAmbig1[G, H, J] : J =!= J = null + implicit def neqAmbig2[I] : I =!= I = null + + implicitly[Int =!= Int] +} diff --git a/test/files/neg/name-lookup-stable.check b/test/files/neg/name-lookup-stable.check index 751df9505e..68d98c4162 100644 --- a/test/files/neg/name-lookup-stable.check +++ b/test/files/neg/name-lookup-stable.check @@ -6,6 +6,6 @@ import ColumnOption._ name-lookup-stable.scala:17: error: reference to PrimaryKey is ambiguous; it is both defined in class A and imported subsequently by import ColumnOption._ - PrimaryKey // was already ambigious in 2.10.3 + PrimaryKey // was already ambiguous in 2.10.3 ^ two errors found diff --git a/test/files/neg/name-lookup-stable.scala b/test/files/neg/name-lookup-stable.scala index 0d862f06e1..2941e05875 100644 --- a/test/files/neg/name-lookup-stable.scala +++ b/test/files/neg/name-lookup-stable.scala @@ -14,7 +14,7 @@ class A { (null: Any) match { case PrimaryKey => } - PrimaryKey // was already ambigious in 2.10.3 + PrimaryKey // was already ambiguous in 2.10.3 } } diff --git a/test/files/neg/t5376.scala b/test/files/neg/t5376.scala index 8da3868566..b1ba41bd54 100644 --- a/test/files/neg/t5376.scala +++ b/test/files/neg/t5376.scala @@ -12,7 +12,7 @@ object Test { "a": Int } - // Import one implict and one non-implicit method with the + // Import one implicit and one non-implicit method with the // same name in the same scope. def m2 = { import O1._ diff --git a/test/files/neg/t6666d.check b/test/files/neg/t6666d.check deleted file mode 100644 index b4785f0129..0000000000 --- a/test/files/neg/t6666d.check +++ /dev/null @@ -1,4 +0,0 @@ -t6666d.scala:7: error: Implementation restriction: access of object TreeOrd$1 from object TreeOrd$2, would require illegal premature access to the unconstructed `this` of class Test - implicit object TreeOrd extends Ordering[K](){ - ^ -one error found diff --git a/test/files/neg/t6810.check b/test/files/neg/t6810.check new file mode 100644 index 0000000000..497ef35070 --- /dev/null +++ b/test/files/neg/t6810.check @@ -0,0 +1,28 @@ +t6810.scala:4: error: unclosed character literal + val y = ' + ^ +t6810.scala:5: error: unclosed character literal +' // but not embedded EOL sequences not represented as escapes +^ +t6810.scala:9: error: unclosed string literal + val Y = " + ^ +t6810.scala:10: error: unclosed string literal +" // obviously not +^ +t6810.scala:20: error: unclosed quoted identifier + val ` + ^ +t6810.scala:21: error: unclosed quoted identifier +` = EOL // not raw string literals aka triple-quoted, multiline strings +^ +t6810.scala:24: error: unclosed character literal + val b = ' + ^ +t6810.scala:25: error: unclosed character literal +' // CR seen as EOL by scanner +^ +t6810.scala:24: error: '=' expected but ';' found. + val b = ' +^ +9 errors found diff --git a/test/files/neg/t6810.scala b/test/files/neg/t6810.scala new file mode 100644 index 0000000000..50c305d70c --- /dev/null +++ b/test/files/neg/t6810.scala @@ -0,0 +1,26 @@ + +trait t6810 { + val x = '\u000A' // char literals accept arbitrary unicode escapes + val y = ' +' // but not embedded EOL sequences not represented as escapes + val z = '\n' // normally, expect this escape + + val X = "\u000A" // it's the same as ordinary string literals + val Y = " +" // obviously not + val Z = "\n" // normally, expect this escape + + val A = """ +""" // which is what these are for + val B = s""" +""" // or the same for interpolated strings + + import scala.compat.Platform.EOL + val `\u000A` = EOL // backquoted identifiers are arbitrary string literals + val ` +` = EOL // not raw string literals aka triple-quoted, multiline strings + + val a = '\u000D' // similar treatment of CR + val b = '
' // CR seen as EOL by scanner + val c = '\r' // traditionally +} diff --git a/test/files/neg/t8597b.scala b/test/files/neg/t8597b.scala index b29d591cb1..cbf0bf1c5a 100644 --- a/test/files/neg/t8597b.scala +++ b/test/files/neg/t8597b.scala @@ -4,7 +4,7 @@ object Unchecked { // t is a fresh pattern type variable, despite our attempts to // backtick our way to the enclosing `t`. Under this interpretation, - // the absense of an unchecked warning is expected. + // the absence of an unchecked warning is expected. (null: Any) match { case _: Some[t] => // no warn } diff --git a/test/files/neg/t8675b.scala b/test/files/neg/t8675b.scala index bffed2141c..b2212fa234 100644 --- a/test/files/neg/t8675b.scala +++ b/test/files/neg/t8675b.scala @@ -9,7 +9,7 @@ object Test { } trait Reportable1[Params, R] - // "missing paramater type" error was swallowed in 2.11.0 leading to a crash + // "missing parameter type" error was swallowed in 2.11.0 leading to a crash // in the backend. // // This error is itself a regression (or at least a change) in 2.11.0-M7, diff --git a/test/files/neg/virtpatmat_exhaust_compound.scala b/test/files/neg/virtpatmat_exhaust_compound.scala index 386c7af98d..4ff04dd06a 100644 --- a/test/files/neg/virtpatmat_exhaust_compound.scala +++ b/test/files/neg/virtpatmat_exhaust_compound.scala @@ -10,7 +10,7 @@ case object O3 extends Base2 case object O4 extends Base with Base2 object Test { - val a /*: Product with Serialiable with Base */ = if (true) O1 else O2 + val a /*: Product with Serializable with Base */ = if (true) O1 else O2 a match { case null => } diff --git a/test/files/pos/t2405.scala b/test/files/pos/t2405.scala index 224b2ce83b..0bc7a771b2 100644 --- a/test/files/pos/t2405.scala +++ b/test/files/pos/t2405.scala @@ -6,14 +6,14 @@ object Test1 { implicitly[Int] } -// Testing for the absense of shadowing #1. +// Testing for the absence of shadowing #1. object Test2 { import A.{x => y} val x = 2 implicitly[Int] } -// Testing for the absense of shadowing #2. +// Testing for the absence of shadowing #2. object Test3 { { import A.{x => y} diff --git a/test/files/neg/t6666d.scala b/test/files/pos/t6666d.scala index 49a688f91b..49a688f91b 100644 --- a/test/files/neg/t6666d.scala +++ b/test/files/pos/t6666d.scala diff --git a/test/files/pos/t8002-nested-scope.scala b/test/files/pos/t8002-nested-scope.scala index a2088bce7a..8ce809e556 100644 --- a/test/files/pos/t8002-nested-scope.scala +++ b/test/files/pos/t8002-nested-scope.scala @@ -1,5 +1,5 @@ // This test serves to capture the status quo, but should really -// emit an accessibiltiy error. +// emit an accessibility error. // `Namers#companionSymbolOf` seems too lenient, and currently doesn't // implement the same-scope checks mentioned: diff --git a/test/files/pos/t9442.scala b/test/files/pos/t9442.scala new file mode 100644 index 0000000000..2ea81e79cb --- /dev/null +++ b/test/files/pos/t9442.scala @@ -0,0 +1,14 @@ +trait Ctx { + trait Tree +} +trait Lst[+A] { + def zip[A1 >: A, B](that: Lst[B]): Nothing +} +class C[@specialized(Int) T] { + def moo(t: T) = { + def foo1(c: Ctx)(l: Lst[c.Tree]) = l zip l + def foo2(c: Ctx)(l: Lst[c.Tree]*) = l(0) zip l(1) + def foo3(c: Ctx)(l: => Lst[c.Tree]) = l zip l + ??? + } +} diff --git a/test/files/run/constrained-types.check b/test/files/run/constrained-types.check index 670d6f49aa..5444cf2088 100644 --- a/test/files/run/constrained-types.check +++ b/test/files/run/constrained-types.check @@ -133,16 +133,16 @@ y: String = hello scala> scala> val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message -<console>:11: error: not found: value e +<console>:12: error: not found: value e val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message ^ -<console>:11: error: not found: value f +<console>:12: error: not found: value f val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message ^ -<console>:11: error: not found: value g +<console>:12: error: not found: value g val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message ^ -<console>:11: error: not found: value h +<console>:12: error: not found: value h val x = 3 : Int @Annot(e+f+g+h) // should have a graceful error message ^ diff --git a/test/files/run/dead-code-elimination.scala b/test/files/run/dead-code-elimination.scala index fd3f2a996a..2291b22f7a 100644 --- a/test/files/run/dead-code-elimination.scala +++ b/test/files/run/dead-code-elimination.scala @@ -10,7 +10,7 @@ // the stack after code elimination. // // Originally, this did not compile, but I included it in the run -// tests because this was ASM-dependand and did not happen for GenJVM. +// tests because this was ASM-dependent and did not happen for GenJVM. // // Thus, we run the code and force the loading of class B -- if the // bytecode is incorrect, it will fail the test. diff --git a/test/files/run/idempotency-case-classes.check b/test/files/run/idempotency-case-classes.check index 5a8d0ad9d3..ea698cec59 100644 --- a/test/files/run/idempotency-case-classes.check +++ b/test/files/run/idempotency-case-classes.check @@ -47,8 +47,7 @@ C(2,3) case <synthetic> def unapply(x$0: C): Option[(Int, Int)] = if (x$0.==(null)) scala.this.None else - Some.apply[(Int, Int)](scala.Tuple2.apply[Int, Int](x$0.x, x$0.y)); - <synthetic> private def readResolve(): Object = C + Some.apply[(Int, Int)](scala.Tuple2.apply[Int, Int](x$0.x, x$0.y)) }; Predef.println(C.apply(2, 3)) } diff --git a/test/files/run/kind-repl-command.check b/test/files/run/kind-repl-command.check index e050fb4bc1..560529ba03 100644 --- a/test/files/run/kind-repl-command.check +++ b/test/files/run/kind-repl-command.check @@ -19,7 +19,7 @@ scala> :k new { def empty = false } AnyRef{def empty: Boolean}'s kind is A scala> :k Nonexisting -<console>:11: error: not found: value Nonexisting +<console>:12: error: not found: value Nonexisting Nonexisting ^ diff --git a/test/files/run/names-defaults.scala b/test/files/run/names-defaults.scala index 7fb4a04546..4159dbdf91 100644 --- a/test/files/run/names-defaults.scala +++ b/test/files/run/names-defaults.scala @@ -192,7 +192,7 @@ object Test extends App { println(argName) // should be 4 test5 { argName = 5 } println(argName) // should be 5 - val a: Unit = test1(a = 10, b = "2") // local values a and b exist, but not ambiuous since they're val's + val a: Unit = test1(a = 10, b = "2") // local values a and b exist, but it's not ambiguous since they're vals // dependent types and copy method diff --git a/test/files/run/nothingTypeNoOpt.scala b/test/files/run/nothingTypeNoOpt.scala index 5c5a20fa3b..454539a4b1 100644 --- a/test/files/run/nothingTypeNoOpt.scala +++ b/test/files/run/nothingTypeNoOpt.scala @@ -26,7 +26,7 @@ class C { } def f5(x: Boolean) = { - // stack heights need to be the smae. ??? looks to the jvm like returning a value of + // stack heights need to be the same. ??? looks to the jvm like returning a value of // type Nothing$, need to drop or throw it. println( if (x) { ???; 10 } diff --git a/test/files/run/reify-repl-fail-gracefully.check b/test/files/run/reify-repl-fail-gracefully.check index 025d377a43..32ed876356 100644 --- a/test/files/run/reify-repl-fail-gracefully.check +++ b/test/files/run/reify-repl-fail-gracefully.check @@ -8,7 +8,7 @@ import scala.reflect.runtime.universe._ scala> scala> reify -<console>:15: error: too few argument lists for macro invocation +<console>:16: error: too few argument lists for macro invocation reify ^ diff --git a/test/files/run/reify_newimpl_22.check b/test/files/run/reify_newimpl_22.check index e69dc60199..985f646579 100644 --- a/test/files/run/reify_newimpl_22.check +++ b/test/files/run/reify_newimpl_22.check @@ -15,7 +15,7 @@ scala> { } println(code.eval) } -<console>:18: free term: Ident(TermName("x")) defined by res0 in <console>:17:14 +<console>:19: free term: Ident(TermName("x")) defined by res0 in <console>:18:14 val code = reify { ^ 2 diff --git a/test/files/run/reify_newimpl_23.check b/test/files/run/reify_newimpl_23.check index 1356d509d3..f60113c69f 100644 --- a/test/files/run/reify_newimpl_23.check +++ b/test/files/run/reify_newimpl_23.check @@ -14,7 +14,7 @@ scala> def foo[T]{ } println(code.eval) } -<console>:16: free type: Ident(TypeName("T")) defined by foo in <console>:15:16 +<console>:17: free type: Ident(TypeName("T")) defined by foo in <console>:16:16 val code = reify { ^ foo: [T]=> Unit diff --git a/test/files/run/reify_newimpl_25.check b/test/files/run/reify_newimpl_25.check index e512cfc52e..9104d8df0b 100644 --- a/test/files/run/reify_newimpl_25.check +++ b/test/files/run/reify_newimpl_25.check @@ -5,7 +5,7 @@ scala> { val tt = implicitly[TypeTag[x.type]] println(tt) } -<console>:14: free term: Ident(TermName("x")) defined by res0 in <console>:13:14 +<console>:15: free term: Ident(TermName("x")) defined by res0 in <console>:14:14 val tt = implicitly[TypeTag[x.type]] ^ TypeTag[x.type] diff --git a/test/files/run/reify_newimpl_26.check b/test/files/run/reify_newimpl_26.check index b203389db1..cbb21854ba 100644 --- a/test/files/run/reify_newimpl_26.check +++ b/test/files/run/reify_newimpl_26.check @@ -4,7 +4,7 @@ scala> def foo[T]{ val tt = implicitly[WeakTypeTag[List[T]]] println(tt) } -<console>:12: free type: Ident(TypeName("T")) defined by foo in <console>:10:16 +<console>:13: free type: Ident(TypeName("T")) defined by foo in <console>:11:16 val tt = implicitly[WeakTypeTag[List[T]]] ^ foo: [T]=> Unit diff --git a/test/files/run/repl-bare-expr.check b/test/files/run/repl-bare-expr.check index f0c488455f..e0a1f4ecd6 100644 --- a/test/files/run/repl-bare-expr.check +++ b/test/files/run/repl-bare-expr.check @@ -1,12 +1,12 @@ scala> 2 ; 3 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 2 ;; ^ res0: Int = 3 scala> { 2 ; 3 } -<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses { 2 ; 3 } ^ res1: Int = 3 @@ -15,16 +15,16 @@ scala> 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Mooo 1 + 2 + 3 } ; bippy+88+11 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ defined object Cow diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check index 35853f10da..6516f4ea90 100644 --- a/test/files/run/repl-parens.check +++ b/test/files/run/repl-parens.check @@ -18,10 +18,10 @@ scala> ( (2 + 2 ) ) res5: Int = 4 scala> 5 ; ( (2 + 2 ) ) ; ((5)) -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; ( (2 + 2 ) ) ;; ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; ( (2 + 2 ) ) ;; ^ res6: Int = 5 @@ -38,16 +38,16 @@ res9: String = 4423 scala> scala> 55 ; ((2 + 2)) ; (1, 2, 3) -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; ((2 + 2)) ;; ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; ((2 + 2)) ;; ^ res10: (Int, Int, Int) = (1,2,3) scala> 55 ; (x: Int) => x + 1 ; () => ((5)) -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; (x: Int) => x + 1 ;; ^ res11: () => Int = <function0> @@ -58,7 +58,7 @@ scala> () => 5 res12: () => Int = <function0> scala> 55 ; () => 5 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ;; ^ res13: () => Int = <function0> diff --git a/test/files/run/repl-paste-2.check b/test/files/run/repl-paste-2.check index 5b6a84144d..dbf5363c0f 100644 --- a/test/files/run/repl-paste-2.check +++ b/test/files/run/repl-paste-2.check @@ -42,7 +42,7 @@ scala> res5 + res6 res1: Int = 690 scala> val x = dingus -<console>:10: error: not found: value dingus +<console>:11: error: not found: value dingus val x = dingus ^ diff --git a/test/files/run/repl-power.check b/test/files/run/repl-power.check index 2a7b7783d9..4e030bd9fa 100644 --- a/test/files/run/repl-power.check +++ b/test/files/run/repl-power.check @@ -25,4 +25,7 @@ m: $r.treedsl.global.Literal = 10 scala> typed(m).tpe // typed is in scope res2: $r.treedsl.global.Type = Int(10) +scala> """escaping is hard, m'kah""" +res3: String = escaping is hard, m'kah + scala> :quit diff --git a/test/files/run/repl-power.scala b/test/files/run/repl-power.scala index 4dfeb37885..5ecaad8723 100644 --- a/test/files/run/repl-power.scala +++ b/test/files/run/repl-power.scala @@ -1,7 +1,9 @@ import scala.tools.partest.ReplTest object Test extends ReplTest { - def code = """ + def tripleQuote(s: String) = "\"\"\"" + s + "\"\"\"" + + def code = s""" :power // guarding against "error: reference to global is ambiguous" global.emptyValDef // "it is imported twice in the same scope by ..." @@ -9,5 +11,6 @@ val tp = ArrayClass[scala.util.Random] // magic with tags tp.memberType(Array_apply) // evidence val m = LIT(10) // treedsl typed(m).tpe // typed is in scope +${tripleQuote("escaping is hard, m'kah")} """.trim } diff --git a/test/files/run/repl-reset.check b/test/files/run/repl-reset.check index b0683fff79..cf4d9a149e 100644 --- a/test/files/run/repl-reset.check +++ b/test/files/run/repl-reset.check @@ -28,13 +28,13 @@ Forgetting all expression results and named terms: $intp, BippyBungus, x1, x2, x Forgetting defined types: BippyBungus scala> x1 + x2 + x3 -<console>:11: error: not found: value x1 +<console>:12: error: not found: value x1 x1 + x2 + x3 ^ -<console>:11: error: not found: value x2 +<console>:12: error: not found: value x2 x1 + x2 + x3 ^ -<console>:11: error: not found: value x3 +<console>:12: error: not found: value x3 x1 + x2 + x3 ^ @@ -42,7 +42,7 @@ scala> val x1 = 4 x1: Int = 4 scala> new BippyBungus -<console>:11: error: not found: type BippyBungus +<console>:12: error: not found: type BippyBungus new BippyBungus ^ diff --git a/test/files/run/repl-serialization.check b/test/files/run/repl-serialization.check index eb62729f5c..bbbf0dcdf1 100644 --- a/test/files/run/repl-serialization.check +++ b/test/files/run/repl-serialization.check @@ -20,6 +20,5 @@ u: U = U evaluating O constructing A == reconstituting into a fresh classloader - evaluating O == evaluating reconstituted lambda constructing A diff --git a/test/files/run/repl-trim-stack-trace.scala b/test/files/run/repl-trim-stack-trace.scala index ea91e32239..c0814905f9 100644 --- a/test/files/run/repl-trim-stack-trace.scala +++ b/test/files/run/repl-trim-stack-trace.scala @@ -12,7 +12,7 @@ f: Nothing scala> f java.lang.Exception: Uh-oh - at .f(<console>:10) + at .f(<console>:11) ... 69 elided scala> def f = throw new Exception("") @@ -20,7 +20,7 @@ f: Nothing scala> f java.lang.Exception: - at .f(<console>:10) + at .f(<console>:11) ... 69 elided scala> def f = throw new Exception @@ -28,7 +28,7 @@ f: Nothing scala> f java.lang.Exception - at .f(<console>:10) + at .f(<console>:11) ... 69 elided scala> :quit""" diff --git a/test/files/run/t1931.scala b/test/files/run/t1931.scala new file mode 100644 index 0000000000..eedfa9b03d --- /dev/null +++ b/test/files/run/t1931.scala @@ -0,0 +1,43 @@ + +import scala.tools.partest.SessionTest + +object Test extends SessionTest { + + def session = +""" +scala> val x: Any = 42 +x: Any = 42 + +scala> x + " works" +res0: String = 42 works + +scala> import Predef.{ any2stringadd => _, _ } +import Predef.{any2stringadd=>_, _} + +scala> x + " works" +<console>:14: error: value + is not a member of Any + x + " works" + ^ + +scala> import Predef._ +import Predef._ + +scala> x + " works" +res2: String = 42 works + +scala> object Predef { def f = 42 } +defined object Predef + +scala> import Predef._ +import Predef._ + +scala> f +<console>:14: error: not found: value f + f + ^ + +scala> Predef.f +res4: Int = 42 + +scala> :quit""" +} diff --git a/test/files/run/t4542.check b/test/files/run/t4542.check index 3ab3eaffd8..6e099222b0 100644 --- a/test/files/run/t4542.check +++ b/test/files/run/t4542.check @@ -5,7 +5,7 @@ scala> @deprecated("foooo", "ReplTest version 1.0-FINAL") class Foo() { defined class Foo scala> val f = new Foo -<console>:11: warning: class Foo is deprecated: foooo +<console>:12: warning: class Foo is deprecated: foooo val f = new Foo ^ f: Foo = Bippy diff --git a/test/files/run/t4594-repl-settings.scala b/test/files/run/t4594-repl-settings.scala index cbd87b5949..f2d1a8b3f8 100644 --- a/test/files/run/t4594-repl-settings.scala +++ b/test/files/run/t4594-repl-settings.scala @@ -15,7 +15,7 @@ object Test extends SessionTest { |scala> :settings -deprecation | |scala> def b = depp - |<console>:11: warning: method depp is deprecated: Please don't do that. + |<console>:12: warning: method depp is deprecated: Please don't do that. | def b = depp | ^ |b: String diff --git a/test/files/run/t5655.check b/test/files/run/t5655.check index 857a5ab556..9191997624 100644 --- a/test/files/run/t5655.check +++ b/test/files/run/t5655.check @@ -6,7 +6,7 @@ scala> import x._ import x._ scala> x -<console>:15: error: reference to x is ambiguous; +<console>:16: error: reference to x is ambiguous; it is imported twice in the same scope by import x._ and import x @@ -14,7 +14,7 @@ and import x ^ scala> x -<console>:15: error: reference to x is ambiguous; +<console>:16: error: reference to x is ambiguous; it is imported twice in the same scope by import x._ and import x diff --git a/test/files/run/t7319.check b/test/files/run/t7319.check index 31923e7119..4d8429e8f2 100644 --- a/test/files/run/t7319.check +++ b/test/files/run/t7319.check @@ -15,21 +15,21 @@ warning: there was one feature warning; re-run with -feature for details convert: [F[X <: F[X]]](builder: F[_ <: F[_]])Int scala> convert(Some[Int](0)) -<console>:15: error: no type parameters for method convert: (builder: F[_ <: F[_]])Int exist so that it can be applied to arguments (Some[Int]) +<console>:16: error: no type parameters for method convert: (builder: F[_ <: F[_]])Int exist so that it can be applied to arguments (Some[Int]) --- because --- argument expression's type is not compatible with formal parameter type; found : Some[Int] required: ?F[_$1] forSome { type _$1 <: ?F[_$2] forSome { type _$2 } } convert(Some[Int](0)) ^ -<console>:15: error: type mismatch; +<console>:16: error: type mismatch; found : Some[Int] required: F[_ <: F[_]] convert(Some[Int](0)) ^ scala> Range(1,2).toArray: Seq[_] -<console>:14: error: polymorphic expression cannot be instantiated to expected type; +<console>:15: error: polymorphic expression cannot be instantiated to expected type; found : [B >: Int]Array[B] required: Seq[_] Range(1,2).toArray: Seq[_] diff --git a/test/files/run/t7747-repl.check b/test/files/run/t7747-repl.check index f19c39e7e1..487daf4878 100644 --- a/test/files/run/t7747-repl.check +++ b/test/files/run/t7747-repl.check @@ -15,13 +15,13 @@ scala> val z = x * y z: Int = 156 scala> 2 ; 3 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 2 ;; ^ res0: Int = 3 scala> { 2 ; 3 } -<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses { 2 ; 3 } ^ res1: Int = 3 @@ -30,16 +30,16 @@ scala> 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Mooo 1 + 2 + 3 } ; bippy+88+11 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; 10 ; case object Cow ; 20 ; class Moo { override def toString = "Moooooo" } ; 30 ; def bippy = { ^ defined object Cow @@ -81,10 +81,10 @@ scala> ( (2 + 2 ) ) res10: Int = 4 scala> 5 ; ( (2 + 2 ) ) ; ((5)) -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; ( (2 + 2 ) ) ;; ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 5 ; ( (2 + 2 ) ) ;; ^ res11: Int = 5 @@ -101,16 +101,16 @@ res14: String = 4423 scala> scala> 55 ; ((2 + 2)) ; (1, 2, 3) -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; ((2 + 2)) ;; ^ -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; ((2 + 2)) ;; ^ res15: (Int, Int, Int) = (1,2,3) scala> 55 ; (x: Int) => x + 1 ; () => ((5)) -<console>:12: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:13: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ; (x: Int) => x + 1 ;; ^ res16: () => Int = <function0> @@ -121,7 +121,7 @@ scala> () => 5 res17: () => Int = <function0> scala> 55 ; () => 5 -<console>:10: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses +<console>:11: warning: a pure expression does nothing in statement position; you may be omitting necessary parentheses 55 ;; ^ res18: () => Int = <function0> @@ -209,13 +209,13 @@ Forgetting all expression results and named terms: $intp, BippyBungus, Bovine, C Forgetting defined types: BippyBungus, Moo, Ruminant scala> x1 + x2 + x3 -<console>:11: error: not found: value x1 +<console>:12: error: not found: value x1 x1 + x2 + x3 ^ -<console>:11: error: not found: value x2 +<console>:12: error: not found: value x2 x1 + x2 + x3 ^ -<console>:11: error: not found: value x3 +<console>:12: error: not found: value x3 x1 + x2 + x3 ^ @@ -223,7 +223,7 @@ scala> val x1 = 4 x1: Int = 4 scala> new BippyBungus -<console>:11: error: not found: type BippyBungus +<console>:12: error: not found: type BippyBungus new BippyBungus ^ diff --git a/test/files/run/t8047.scala b/test/files/run/t8047.scala index f5660541e8..9ec8c1dc56 100644 --- a/test/files/run/t8047.scala +++ b/test/files/run/t8047.scala @@ -1,7 +1,7 @@ object Test extends App { import scala.reflect.runtime.universe._ // - // x's owner is outer Test scope. Previosly the quasiquote expansion + // x's owner is outer Test scope. Previously the quasiquote expansion // looked like: // // object Test { diff --git a/test/files/run/t8346.check b/test/files/run/t8346.check deleted file mode 100644 index 1ba5c31abe..0000000000 --- a/test/files/run/t8346.check +++ /dev/null @@ -1,6 +0,0 @@ -BitSet: List(invariant, invariant, invariant, invariant) -HashSet: List(covariant (true), covariant (true), covariant (true), covariant (true)) -ListSet: List(covariant (true), covariant (true), covariant (true), covariant (true)) -SortedSet: List(invariant, invariant, invariant, invariant) -TreeSet: List(invariant, invariant, invariant, invariant) -ValueSet: invariant diff --git a/test/files/run/t8346.scala b/test/files/run/t8346.scala deleted file mode 100644 index 5f3df84174..0000000000 --- a/test/files/run/t8346.scala +++ /dev/null @@ -1,34 +0,0 @@ -object Test extends App { - import reflect.ClassTag - - object SomeEnum extends Enumeration { - val one, two, three, four = Value - } - - def sctor[A <: Set[Int]](f: Int => A)(implicit A: ClassTag[A]) - : (String, Int => Set[Int]) = - (A.runtimeClass.getSimpleName, f) - - val inits: Seq[(String, Int => Set[Int])] = { - import collection.immutable.{Seq => _, _} - Seq(sctor(BitSet(_)), - sctor(HashSet(_)), - sctor(ListSet(_)), - sctor(SortedSet(_)), - sctor(TreeSet(_))) - } - - def sVarInfo[A](sa: Set[A]): String = { - val saa = sa.toSet[Any] - if (sa eq saa) s"""covariant (${(saa + "hi") contains "hi"})""" - else "invariant" - } - - inits foreach {case (name, singleton) => - print(s"${name}: ") - val one = singleton(1) - println(Seq(2,3,4).scanLeft(one)(_ + _) map sVarInfo toList) - } - - println(s"ValueSet: ${sVarInfo(SomeEnum.values)}") -} diff --git a/test/files/run/t9170.scala b/test/files/run/t9170.scala index d6cf516615..f39467bc25 100644 --- a/test/files/run/t9170.scala +++ b/test/files/run/t9170.scala @@ -8,17 +8,17 @@ object Test extends SessionTest { def session = """ scala> object Y { def f[A](a: => A) = 1 ; def f[A](a: => Either[Exception, A]) = 2 } -<console>:10: error: double definition: -def f[A](a: => A): Int at line 10 and -def f[A](a: => Either[Exception,A]): Int at line 10 +<console>:11: error: double definition: +def f[A](a: => A): Int at line 11 and +def f[A](a: => Either[Exception,A]): Int at line 11 have same type after erasure: (a: Function0)Int object Y { def f[A](a: => A) = 1 ; def f[A](a: => Either[Exception, A]) = 2 } ^ scala> object Y { def f[A](a: => A) = 1 ; def f[A](a: => Either[Exception, A]) = 2 } -<console>:10: error: double definition: -def f[A](a: => A): Int at line 10 and -def f[A](a: => Either[Exception,A]): Int at line 10 +<console>:11: error: double definition: +def f[A](a: => A): Int at line 11 and +def f[A](a: => Either[Exception,A]): Int at line 11 have same type after erasure: (a: Function0)Int object Y { def f[A](a: => A) = 1 ; def f[A](a: => Either[Exception, A]) = 2 } ^ @@ -27,9 +27,9 @@ scala> object Y { | def f[A](a: => A) = 1 | def f[A](a: => Either[Exception, A]) = 2 | } -<console>:12: error: double definition: -def f[A](a: => A): Int at line 11 and -def f[A](a: => Either[Exception,A]): Int at line 12 +<console>:13: error: double definition: +def f[A](a: => A): Int at line 12 and +def f[A](a: => Either[Exception,A]): Int at line 13 have same type after erasure: (a: Function0)Int def f[A](a: => Either[Exception, A]) = 2 ^ @@ -44,9 +44,9 @@ object Y { // Exiting paste mode, now interpreting. -<console>:12: error: double definition: -def f[A](a: => A): Int at line 11 and -def f[A](a: => Either[Exception,A]): Int at line 12 +<console>:13: error: double definition: +def f[A](a: => A): Int at line 12 and +def f[A](a: => Either[Exception,A]): Int at line 13 have same type after erasure: (a: Function0)Int def f[A](a: => Either[Exception, A]) = 2 ^ diff --git a/test/files/run/t9206.scala b/test/files/run/t9206.scala index 872c980fe4..406798104e 100644 --- a/test/files/run/t9206.scala +++ b/test/files/run/t9206.scala @@ -7,14 +7,14 @@ object Test extends SessionTest { def session = s"""| |scala> val i: Int = "foo" - |<console>:10: error: type mismatch; + |<console>:11: error: type mismatch; | found : String("foo") | required: Int | val i: Int = "foo" | ^ | |scala> { val j = 42 ; val i: Int = "foo" + j } - |<console>:11: error: type mismatch; + |<console>:12: error: type mismatch; | found : String | required: Int | { val j = 42 ; val i: Int = "foo" + j } diff --git a/test/files/run/t9375.check b/test/files/run/t9375.check new file mode 100644 index 0000000000..8f43fab025 --- /dev/null +++ b/test/files/run/t9375.check @@ -0,0 +1,60 @@ + konstruktor: class A + konstruktor: class A$O$12$ + konstruktor: class A$$anon$1 + konstruktor: class A$A + konstruktor: class A$C + konstruktor: class C + konstruktor: class T$O$15$ + konstruktor: class T$$anon$2 + konstruktor: class T$A + konstruktor: class T$C + konstruktor: class A$N$ + konstruktor: class T$N$ +serializing outer objects should not initialize any nested objects +now initializing nested objects + konstruktor: class A$O$ + konstruktor: class A$Op$ + konstruktor: class A$N$O$ + konstruktor: class A$N$Op$ + konstruktor: class A$A$O$ + konstruktor: class A$A$Op$ + konstruktor: class A$T$O$ + konstruktor: class A$T$Op$ + konstruktor: class A$O$11$ + konstruktor: class A$O$13$ + konstruktor: class A$$anon$1$O$ + konstruktor: class A$$anon$1$Op$ + konstruktor: class T$O$ + konstruktor: class T$Op$ + konstruktor: class T$N$O$ + konstruktor: class T$N$Op$ + konstruktor: class T$A$O$ + konstruktor: class T$A$Op$ + konstruktor: class T$T$O$ + konstruktor: class T$T$Op$ + konstruktor: class T$O$14$ + konstruktor: class T$O$16$ + konstruktor: class T$$anon$2$O$ + konstruktor: class T$$anon$2$Op$ +no object konstruktors called when serializing / deserializing objects (starting at the outer or the object itself) +deserializing outer objects with non-initialized inners again +accessing modules triggers initialization + konstruktor: class A$O$ + konstruktor: class A$Op$ + konstruktor: class A$N$O$ + konstruktor: class A$N$Op$ +deserializing creates a new object graph, including new scala 'object' instances, no matter where serialization starts +init static module M and field v + konstruktor: class M$ + konstruktor: class M$O$18$ +serDeser does not initialize nested static modules +init M.O + konstruktor: class M$O$ +serDeser nested static module +objects declared in field decls are not static modules, so they deserialize to new instances +init lazy val M.w +objects declared in lazy val are not static modules either + konstruktor: class M$O$19$ +object declared in a function: new instance created on each invocation + konstruktor: class M$O$20$ + konstruktor: class M$O$20$ diff --git a/test/files/run/t9375.scala b/test/files/run/t9375.scala new file mode 100644 index 0000000000..3995b38666 --- /dev/null +++ b/test/files/run/t9375.scala @@ -0,0 +1,276 @@ +import java.io._ + +object SerDes { + def serialize(obj: AnyRef): Array[Byte] = { + val buffer = new ByteArrayOutputStream + val out = new ObjectOutputStream(buffer) + out.writeObject(obj) + buffer.toByteArray + } + + def deserialize(a: Array[Byte]): AnyRef = { + val in = new ObjectInputStream(new ByteArrayInputStream(a)) + in.readObject + } + + def serializeDeserialize[T <: AnyRef](obj: T) = deserialize(serialize(obj)).asInstanceOf[T] +} + +import SerDes._ + +// tests to make sure that de-serializing an object does not run its constructor + +trait S extends Serializable { + println(" konstruktor: " + this.getClass) +} + +trait SE extends S { + def outer: Object +} + +class A extends S { + object O extends SE { def outer = A.this } + private[this] object Op extends SE { def outer = A.this } + def P: SE = Op + + object N extends S { + object O extends SE { def outer = N } + private[this] object Op extends SE { def outer = N } + def P: SE = Op + } + + class A extends S { + object O extends SE { def outer = A.this } + private[this] object Op extends SE { def outer = A.this } + def P: SE = Op + } + + trait T extends S { + object O extends SE { def outer = T.this } + private[this] object Op extends SE { def outer = T.this } + def P: SE = Op + } + class C extends T + + def u: SE = { + object O extends SE { def outer = A.this } + O + } + + val v: SE = { + object O extends SE { def outer = A.this } + O + } + + val f: () => SE = () => { + object O extends SE { def outer = A.this } + O + } + + trait GetObj { def O: SE; def P: SE } + val a: GetObj = new GetObj with S { + def anonThis = this + object O extends SE { def outer = anonThis } + private[this] object Op extends SE { def outer = anonThis } + def P: SE = Op + } +} + +trait T extends S { + object O extends SE { def outer = T.this } + private[this] object Op extends SE { def outer = T.this } + def P: SE = Op + + object N extends S { + object O extends SE { def outer = N } + private[this] object Op extends SE { def outer = N } + def P: SE = Op + } + + class A extends S { + object O extends SE { def outer = A.this } + private[this] object Op extends SE { def outer = A.this } + def P: SE = Op + } + + trait T extends S { + object O extends SE { def outer = T.this } + private[this] object Op extends SE { def outer = T.this } + def P: SE = Op + } + class C extends T + + def u: SE = { + object O extends SE { def outer = T.this } + O + } + + val v: SE = { + object O extends SE { def outer = T.this } + O + } + + val f: () => SE = () => { + object O extends SE { def outer = T.this } + O + } + + trait GetObj { def O: SE; def P: SE } + val a: GetObj = new GetObj with S { + def anonThis = this + object O extends SE { def outer = anonThis } + private[this] object Op extends SE { def outer = anonThis } + def P: SE = Op + } +} + +class C extends T + +object DeserializeModuleNoConstructor { + def t(): Unit = { + val a = new A + val aa = new a.A + val ac = new a.C + + val c = new C + val ca = new c.A + val cc = new c.C + + val outers: List[Object] = List( + a, a.N, aa, ac, a.a, + c, c.N, ca, cc, c.a + ) + + println("serializing outer objects should not initialize any nested objects") + + val serANotInit = serialize(a) + outers foreach serializeDeserialize + + println("now initializing nested objects") + + val os: List[(SE, Object)] = List( + a.O -> a, + a.P -> a, + a.N.O -> a.N, + a.N.P -> a.N, + aa.O -> aa, + aa.P -> aa, + ac.O -> ac, + ac.P -> ac, + a.u -> a, + a.v -> a, + a.f() -> a, + a.a.O -> a.a, + a.a.P -> a.a, + + c.O -> c, + c.P -> c, + c.N.O -> c.N, + c.N.P -> c.N, + ca.O -> ca, + ca.P -> ca, + cc.O -> cc, + cc.P -> cc, + c.u -> c, + c.v -> c, + c.f() -> c, + c.a.O -> c.a, + c.a.P -> c.a + ) + + println("no object konstruktors called when serializing / deserializing objects (starting at the outer or the object itself)") + + for ((obj, outer) <- os) { + assert(obj.outer eq outer, s"${obj.outer} of $obj -- $outer") + serializeDeserialize(obj) + serializeDeserialize(outer) + } + + println("deserializing outer objects with non-initialized inners again") + val aNotInit = deserialize(serANotInit).asInstanceOf[A] + + println("accessing modules triggers initialization") + aNotInit.O + aNotInit.P + aNotInit.N.O + aNotInit.N.P + + println("deserializing creates a new object graph, including new scala 'object' instances, no matter where serialization starts") + val deserializedAs: List[A] = List( + serializeDeserialize(a), + serializeDeserialize(a.O).outer.asInstanceOf[A], + serializeDeserialize(a.P).outer.asInstanceOf[A], + serializeDeserialize(a.v).outer.asInstanceOf[A] + ) + for (aSD <- deserializedAs) { + assert(aSD ne a) + assert(aSD.O ne a.O) + assert(aSD.P ne a.P) + assert(aSD.N ne a.N) + assert(aSD.N.O ne a.N.O) + assert(aSD.N.P ne a.N.P) + assert(aSD.v ne a.v) + assert(aSD.a.O ne a.a.O) + assert(aSD.a.P ne a.a.P) + } + } +} + +// tests for serializing / deserializing static modules + +object M extends S { + object O extends S + + def u: S = { + object O extends S + O + } + + val v: S = { + object O extends S + O + } + + lazy val w: S = { + object O extends S + O + } + + val f: () => S = () => { + object O extends S + O + } +} + +object SerializingStaticModules { + def t(): Unit = { + println("init static module M and field v") + M + + println("serDeser does not initialize nested static modules") + assert(serializeDeserialize(M) eq M) + + println("init M.O") + M.O + + println("serDeser nested static module") + assert(serializeDeserialize(M.O) eq M.O) + + println("objects declared in field decls are not static modules, so they deserialize to new instances") + assert(serializeDeserialize(M.v) ne M.v) + + println("init lazy val M.w") + + println("objects declared in lazy val are not static modules either") + assert(serializeDeserialize(M.w) ne M.w) + + println("object declared in a function: new instance created on each invocation") + assert(M.f() ne M.f()) + } +} + + +object Test extends App { + DeserializeModuleNoConstructor.t() + SerializingStaticModules.t() +} diff --git a/test/files/run/t9425.scala b/test/files/run/t9425.scala new file mode 100644 index 0000000000..f251cc8579 --- /dev/null +++ b/test/files/run/t9425.scala @@ -0,0 +1,8 @@ +class C { case class Foo private (x: Int); Foo.apply(0) } + +object Test { + def test(c: C) = {import c.Foo; Foo.apply(0)} + def main(args: Array[String]): Unit = { + test(new C) + } +} diff --git a/test/files/run/toolbox_expand_macro.check b/test/files/run/toolbox_expand_macro.check new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/files/run/toolbox_expand_macro.check @@ -0,0 +1 @@ +42 diff --git a/test/files/run/toolbox_expand_macro.scala b/test/files/run/toolbox_expand_macro.scala new file mode 100644 index 0000000000..a52e449168 --- /dev/null +++ b/test/files/run/toolbox_expand_macro.scala @@ -0,0 +1,23 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.{ToolBox} + +object Test extends App { + val toolBox = cm.mkToolBox() + val x = 21 + val runtimeMacro = + q"""object RuntimeMacro { + import scala.reflect.macros.whitebox.Context + import scala.language.experimental.macros + + def add(y: Int): Int = macro addImpl + def addImpl(c: Context)(y: c.Expr[Int]): c.Expr[Int] = { + import c.universe._ + val x = $x + c.Expr[Int](q"$$x + $$y") + } + }""" + val s = toolBox.define(runtimeMacro) + println(toolBox.eval(q"$s.add(21)")) +} diff --git a/test/files/run/xMigration.check b/test/files/run/xMigration.check index 79ce544493..cd860bf394 100644 --- a/test/files/run/xMigration.check +++ b/test/files/run/xMigration.check @@ -10,7 +10,7 @@ res1: Iterable[String] = MapLike(eis) scala> :setting -Xmigration:any scala> Map(1 -> "eis").values // warn -<console>:11: warning: method values in trait MapLike has changed semantics in version 2.8.0: +<console>:12: warning: method values in trait MapLike has changed semantics in version 2.8.0: `values` returns `Iterable[B]` rather than `Iterator[B]`. Map(1 -> "eis").values // warn ^ @@ -24,7 +24,7 @@ res3: Iterable[String] = MapLike(eis) scala> :setting -Xmigration:2.7 scala> Map(1 -> "eis").values // warn -<console>:11: warning: method values in trait MapLike has changed semantics in version 2.8.0: +<console>:12: warning: method values in trait MapLike has changed semantics in version 2.8.0: `values` returns `Iterable[B]` rather than `Iterator[B]`. Map(1 -> "eis").values // warn ^ @@ -38,7 +38,7 @@ res5: Iterable[String] = MapLike(eis) scala> :setting -Xmigration // same as :any scala> Map(1 -> "eis").values // warn -<console>:11: warning: method values in trait MapLike has changed semantics in version 2.8.0: +<console>:12: warning: method values in trait MapLike has changed semantics in version 2.8.0: `values` returns `Iterable[B]` rather than `Iterator[B]`. Map(1 -> "eis").values // warn ^ diff --git a/test/files/scalacheck/avl.scala b/test/files/scalacheck/avl.scala deleted file mode 100644 index 4cfacaf407..0000000000 --- a/test/files/scalacheck/avl.scala +++ /dev/null @@ -1,112 +0,0 @@ -import org.scalacheck.Gen -import org.scalacheck.Prop.forAll -import org.scalacheck.Properties - -package scala.collection.mutable { - - /** - * Property of an AVL Tree : Any node of the tree has a balance value beetween in [-1; 1] - */ - abstract class AVLTreeTest(name: String) extends Properties(name) { - - def `2^`(n: Int) = (1 to n).fold(1)((a, b) => b*2) - - def capacityMax(depth: Int): Int = `2^`(depth+1) - 1 - - def minDepthForCapacity(x: Int): Int = { - var depth = 0 - while(capacityMax(depth) < x) - depth += 1 - depth - } - - def numberOfElementsInLeftSubTree(n: Int): collection.immutable.IndexedSeq[Int] = { - val mid = n/2 + n%2 - ((1 until mid) - .filter { i => math.abs(minDepthForCapacity(i) - minDepthForCapacity(n-i)) < 2 } - .flatMap { i => Seq(i, n-(i+1)) }).toIndexedSeq.distinct - } - - def makeAllBalancedTree[A](elements: List[A]): List[AVLTree[A]] = elements match { - case Nil => Leaf::Nil - case first::Nil => Node(first, Leaf, Leaf)::Nil - case first::second::Nil => Node(second, Node(first, Leaf, Leaf), Leaf)::Node(first, Leaf, Node(second, Leaf, Leaf))::Nil - case first::second::third::Nil => Node(second, Node(first, Leaf, Leaf), Node(third, Leaf, Leaf))::Nil - case _ => { - val combinations = for { - left <- numberOfElementsInLeftSubTree(elements.size) - root = elements(left) - right = elements.size - (left + 1) - } yield (root, left, right) - (combinations.flatMap(triple => for { - l <- makeAllBalancedTree(elements.take(triple._2)) - r <- makeAllBalancedTree(elements.takeRight(triple._3)) - } yield Node(triple._1, l, r))).toList - } - } - - def genInput: org.scalacheck.Gen[(Int, List[AVLTree[Int]])] = for { - size <- org.scalacheck.Gen.choose(20, 25) - elements <- org.scalacheck.Gen.listOfN(size, org.scalacheck.Gen.choose(0, 1000)) - selected <- org.scalacheck.Gen.choose(0, 1000) - } yield { - // selected mustn't be in elements already - val list = makeAllBalancedTree(elements.sorted.distinct.map(_*2)) - (selected*2+1, list) - } - - def genInputDelete: org.scalacheck.Gen[(Int, List[AVLTree[Int]])] = for { - size <- org.scalacheck.Gen.choose(20, 25) - elements <- org.scalacheck.Gen.listOfN(size, org.scalacheck.Gen.choose(0, 1000)) - e = elements.sorted.distinct - selected <- org.scalacheck.Gen.choose(0, e.size-1) - } yield { - // selected must be in elements already - val list = makeAllBalancedTree(e) - (e(selected), list) - } - } - - trait AVLInvariants { - self: AVLTreeTest => - - def isBalanced[A](t: AVLTree[A]): Boolean = t match { - case node: Node[A] => math.abs(node.balance) < 2 && (List(node.left, node.right) forall isBalanced) - case Leaf => true - } - - def setup(invariant: AVLTree[Int] => Boolean) = forAll(genInput) { - case (selected: Int, trees: List[AVLTree[Int]]) => - trees.map(tree => invariant(tree)).fold(true)((a, b) => a && b) - } - - property("Every tree is initially balanced.") = setup(isBalanced) - } - - object TestInsert extends AVLTreeTest("Insert") with AVLInvariants { - import math.Ordering.Int - property("`insert` creates a new tree containing the given element. The tree remains balanced.") = forAll(genInput) { - case (selected: Int, trees: List[AVLTree[Int]]) => - trees.map(tree => { - val modifiedTree = tree.insert(selected, Int) - modifiedTree.contains(selected, Int) && isBalanced(modifiedTree) - }).fold(true)((a, b) => a && b) - } - } - - object TestRemove extends AVLTreeTest("Remove") with AVLInvariants { - import math.Ordering.Int - property("`remove` creates a new tree without the given element. The tree remains balanced.") = forAll(genInputDelete) { - case (selected: Int, trees: List[AVLTree[Int]]) => - trees.map(tree => { - val modifiedTree = tree.remove(selected, Int) - tree.contains(selected, Int) && !modifiedTree.contains(selected, Int) && isBalanced(modifiedTree) - }).fold(true)((a, b) => a && b) - } - } -} - -object Test extends Properties("AVL") { - include(scala.collection.mutable.TestInsert) - include(scala.collection.mutable.TestRemove) -} |