diff options
24 files changed, 263 insertions, 92 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala index 3a97089d51..2965db17c6 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenSymbols.scala @@ -93,7 +93,7 @@ trait GenSymbols { // todo. make sure that free methods and free local defs work correctly if (sym.isExistential) reifySymDef(sym) else if (sym.isTerm) reifyFreeTerm(Ident(sym)) - else reifyFreeType(Ident(sym)) + else reifyFreeType(Ident(sym)) // TODO: reify refinement classes } } diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 1617db7517..81e96b76ac 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -1214,7 +1214,26 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** Have we already supplemented the error message of a compiler crash? */ private[nsc] final var supplementedError = false - private val unitbuf = new mutable.ListBuffer[CompilationUnit] + private class SyncedCompilationBuffer { self => + private val underlying = new mutable.ArrayBuffer[CompilationUnit] + def size = synchronized { underlying.size } + def +=(cu: CompilationUnit): this.type = { synchronized { underlying += cu }; this } + def head: CompilationUnit = synchronized{ underlying.head } + def apply(i: Int): CompilationUnit = synchronized { underlying(i) } + def iterator: Iterator[CompilationUnit] = new collection.AbstractIterator[CompilationUnit] { + private var used = 0 + def hasNext = self.synchronized{ used < underlying.size } + def next = self.synchronized { + if (!hasNext) throw new NoSuchElementException("next on empty Iterator") + used += 1 + underlying(used-1) + } + } + def toList: List[CompilationUnit] = synchronized{ underlying.toList } + } + + private val unitbuf = new SyncedCompilationBuffer + val compiledFiles = new mutable.HashSet[String] /** A map from compiled top-level symbols to their source files */ @@ -1225,9 +1244,8 @@ class Global(var currentSettings: Settings, var reporter: Reporter) private var phasec: Int = 0 // phases completed private var unitc: Int = 0 // units completed this phase - private var _unitbufSize = 0 - def size = _unitbufSize + def size = unitbuf.size override def toString = "scalac Run for:\n " + compiledFiles.toList.sorted.mkString("\n ") // Calculate where to stop based on settings -Ystop-before or -Ystop-after. @@ -1452,7 +1470,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** add unit to be compiled in this run */ private def addUnit(unit: CompilationUnit) { unitbuf += unit - _unitbufSize += 1 // counting as they're added so size is cheap compiledFiles += unit.source.file.path } private def checkDeprecatedSettings(unit: CompilationUnit) { @@ -1468,11 +1485,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /* !!! Note: changing this to unitbuf.toList.iterator breaks a bunch of tests in tests/res. This is bad, it means the resident compiler relies on an iterator of a mutable data structure reflecting changes - made to the underlying structure (in whatever accidental way it is - currently depending upon.) + made to the underlying structure. */ def units: Iterator[CompilationUnit] = unitbuf.iterator - + def registerPickle(sym: Symbol): Unit = () /** does this run compile given class, module, or case factory? */ diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 960c277f67..fdfb1f2efc 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -509,11 +509,14 @@ trait SeqLike[+A, +Repr] extends Any with IterableLike[A, Repr] with GenSeqLike[ } def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { + if (index < 0) throw new IndexOutOfBoundsException(index.toString) val b = bf(repr) val (prefix, rest) = this.splitAt(index) + val restColl = toCollection(rest) + if (restColl.isEmpty) throw new IndexOutOfBoundsException(index.toString) b ++= toCollection(prefix) b += elem - b ++= toCollection(rest).view.tail + b ++= restColl.view.tail b.result() } diff --git a/src/library/scala/collection/concurrent/TrieMap.scala b/src/library/scala/collection/concurrent/TrieMap.scala index 6632f30e51..fccc1d81b9 100644 --- a/src/library/scala/collection/concurrent/TrieMap.scala +++ b/src/library/scala/collection/concurrent/TrieMap.scala @@ -655,8 +655,8 @@ extends scala.collection.concurrent.Map[K, V] /* internal methods */ private def writeObject(out: java.io.ObjectOutputStream) { - out.writeObject(hashf) - out.writeObject(ef) + out.writeObject(hashingobj) + out.writeObject(equalityobj) val it = iterator while (it.hasNext) { diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index 7f54692c8b..e76825cea9 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -381,6 +381,12 @@ final class ListBuffer[A] this } + /** Returns an iterator over this `ListBuffer`. The iterator will reflect + * changes made to the underlying `ListBuffer` beyond the next element; + * the next element's value is cached so that `hasNext` and `next` are + * guaranteed to be consistent. In particular, an empty `ListBuffer` + * will give an empty iterator even if the `ListBuffer` is later filled. + */ override def iterator: Iterator[A] = new AbstractIterator[A] { // Have to be careful iterating over mutable structures. // This used to have "(cursor ne last0)" as part of its hasNext @@ -389,22 +395,15 @@ final class ListBuffer[A] // a structure while iterating, but we should never return hasNext == true // on exhausted iterators (thus creating exceptions) merely because // values were changed in-place. - var cursor: List[A] = null - var delivered = 0 - - // Note: arguably this should not be a "dynamic test" against - // the present length of the buffer, but fixed at the size of the - // buffer when the iterator is created. At the moment such a - // change breaks tests: see comment on def units in Global.scala. - def hasNext: Boolean = delivered < ListBuffer.this.length + var cursor: List[A] = if (ListBuffer.this.isEmpty) Nil else start + + def hasNext: Boolean = cursor ne Nil def next(): A = - if (!hasNext) - throw new NoSuchElementException("next on empty Iterator") + if (!hasNext) throw new NoSuchElementException("next on empty Iterator") else { - if (cursor eq null) cursor = start - else cursor = cursor.tail - delivered += 1 - cursor.head + val ans = cursor.head + cursor = cursor.tail + ans } } diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index ad451f6e0d..d60ea73814 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -1144,7 +1144,7 @@ trait Types /** A class for this-types of the form <sym>.this.type */ abstract case class ThisType(sym: Symbol) extends SingletonType with ThisTypeApi { - if (!sym.isClass) { + if (!sym.isClass && !sym.isFreeType) { // SI-6640 allow StubSymbols to reveal what's missing from the classpath before we trip the assertion. sym.failIfStub() abort(s"ThisType($sym) for sym which is not a class") @@ -4103,24 +4103,44 @@ trait Types ) } - /** Does member `sym1` of `tp1` have a stronger type - * than member `sym2` of `tp2`? + /** Does member `symLo` of `tpLo` have a stronger type + * than member `symHi` of `tpHi`? */ - protected[internal] def specializesSym(tp1: Type, sym1: Symbol, tp2: Type, sym2: Symbol, depth: Depth): Boolean = { - require((sym1 ne NoSymbol) && (sym2 ne NoSymbol), ((tp1, sym1, tp2, sym2, depth))) - val info1 = tp1.memberInfo(sym1) - val info2 = tp2.memberInfo(sym2).substThis(tp2.typeSymbol, tp1) - //System.out.println("specializes "+tp1+"."+sym1+":"+info1+sym1.locationString+" AND "+tp2+"."+sym2+":"+info2)//DEBUG - ( sym2.isTerm && isSubType(info1, info2, depth) && (!sym2.isStable || sym1.isStable) && (!sym1.hasVolatileType || sym2.hasVolatileType) - || sym2.isAbstractType && { - val memberTp1 = tp1.memberType(sym1) - // println("kinds conform? "+(memberTp1, tp1, sym2, kindsConform(List(sym2), List(memberTp1), tp2, sym2.owner))) - info2.bounds.containsType(memberTp1) && - kindsConform(List(sym2), List(memberTp1), tp1, sym1.owner) - } - || sym2.isAliasType && tp2.memberType(sym2).substThis(tp2.typeSymbol, tp1) =:= tp1.memberType(sym1) //@MAT ok - ) - } + protected[internal] def specializesSym(preLo: Type, symLo: Symbol, preHi: Type, symHi: Symbol, depth: Depth): Boolean = + (symHi.isAliasType || symHi.isTerm || symHi.isAbstractType) && { + // only now that we know symHi is a viable candidate ^^^^^^^, do the expensive checks: ----V + require((symLo ne NoSymbol) && (symHi ne NoSymbol), ((preLo, symLo, preHi, symHi, depth))) + + val tpHi = preHi.memberInfo(symHi).substThis(preHi.typeSymbol, preLo) + + // Should we use memberType or memberInfo? + // memberType transforms (using `asSeenFrom`) `sym.tpe`, + // whereas memberInfo performs the same transform on `sym.info`. + // For term symbols, this ends up being the same thing (`sym.tpe == sym.info`). + // For type symbols, however, the `.info` of an abstract type member + // is defined by its bounds, whereas its `.tpe` is a `TypeRef` to that type symbol, + // so that `sym.tpe <:< sym.info`, but not the other way around. + // + // Thus, for the strongest (correct) result, + // we should use `memberType` on the low side. + // + // On the high side, we should use the result appropriate + // for the right side of the `<:<` above (`memberInfo`). + val tpLo = preLo.memberType(symLo) + + debuglog(s"specializesSymHi: $preHi . $symHi : $tpHi") + debuglog(s"specializesSymLo: $preLo . $symLo : $tpLo") + + if (symHi.isTerm) + (isSubType(tpLo, tpHi, depth) && + (!symHi.isStable || symLo.isStable) && // sub-member must remain stable + (!symLo.hasVolatileType || symHi.hasVolatileType)) // sub-member must not introduce volatility + else if (symHi.isAbstractType) + ((tpHi.bounds containsType tpLo) && + kindsConform(symHi :: Nil, tpLo :: Nil, preLo, symLo.owner)) + else // we know `symHi.isAliasType` (see above) + tpLo =:= tpHi + } /** A function implementing `tp1` matches `tp2`. */ final def matchesType(tp1: Type, tp2: Type, alwaysMatchSimple: Boolean): Boolean = { diff --git a/test/files/neg/t0764.check b/test/files/neg/t0764.check new file mode 100644 index 0000000000..0c7cff1e1e --- /dev/null +++ b/test/files/neg/t0764.check @@ -0,0 +1,7 @@ +t0764.scala:13: error: type mismatch; + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + new Main[AType]( (value: AType).prepend ) + ^ +one error found diff --git a/test/files/neg/t0764.scala b/test/files/neg/t0764.scala new file mode 100644 index 0000000000..9f77a59414 --- /dev/null +++ b/test/files/neg/t0764.scala @@ -0,0 +1,45 @@ +class Top[A] { + type AType = A +} + +trait Node { outer => + type T <: Node + def prepend = new Node { type T = outer.type } +} + +class Main[NextType <: Node](value: Node { type T = NextType }) + extends Top[Node { type T = NextType }] { + + new Main[AType]( (value: AType).prepend ) +} + +/* we've been back-and-forth on this one -- see PRs on SI-8177 for the reasoning +I think it should compile and that the following error is due to broken =:= on existentials + found : Node{type T = _1.type} where val _1: Node{type T = NextType} + required: Node{type T = Main.this.AType} + (which expands to) Node{type T = Node{type T = NextType}} + +I claim (omitting the forSome for brevity, even though the premature skolemization is probably the issue) +_1.type =:= Main.this.AType +because +(1) _1.type <:< Main.this.AType and (2) Main.this.AType <:< _1.type +(1), because: +_1.type <:< Node{type T = NextType} (because skolemization and _1's upper bound) +(2), because: +Node{type T = NextType} <:< _1.type forSome val _1: Node{type T = NextType} +because: +Node{type T = NextType} <:< T forSome {type T <: Node{type T = NextType} with Singleton} +because +Node{type T = NextType} <:< Node{type T = NextType} with Singleton + +hmmm.. might the with Singleton be throwing a wrench in our existential house? + +Behold the equivalent program which type checks without the fix for SI-8177. +(Expand type alias, convert type member to type param; +note the covariance to encode subtyping on type members.) + +class Node[+T <: Node[_]] { def prepend = new Node[this.type] } +class Main[NextType <: Node[_]](value: Node[NextType]) { + new Main(value.prepend) +} +*/
\ No newline at end of file diff --git a/test/files/neg/t0764b.check b/test/files/neg/t0764b.check new file mode 100644 index 0000000000..4040954e7c --- /dev/null +++ b/test/files/neg/t0764b.check @@ -0,0 +1,47 @@ +t0764b.scala:27: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.NodeAlias[p1.t0764.NodeAlias[A]] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:28: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.NodeAlias[p1.t0764.Node{type T = A}] + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:34: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.Node{type T = p1.t0764.NodeAlias[A]} + (which expands to) p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:35: error: type mismatch; + found : p1.t0764.Node{type T = p1.t0764.<refinement>.type} + required: p1.t0764.Node{type T = p1.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:51: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.NodeAlias[p2.t0764.NodeAlias[A]] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main1[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:52: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.NodeAlias[p2.t0764.Node{type T = A}] + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main1[Node { type T = A }](v.prepend) // fail + ^ +t0764b.scala:58: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.Node{type T = p2.t0764.NodeAlias[A]} + (which expands to) p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f2 = new Main2[NodeAlias[A]](v.prepend) // fail + ^ +t0764b.scala:59: error: type mismatch; + found : p2.t0764.Node{type T = p2.t0764.<refinement>.type} + required: p2.t0764.Node{type T = p2.t0764.Node{type T = A}} + private[this] def f3 = new Main2[Node { type T = A }](v.prepend) // fail + ^ +8 errors found diff --git a/test/files/pos/t0764b.scala b/test/files/neg/t0764b.scala index 6ae3c105c9..14c623c67a 100644 --- a/test/files/pos/t0764b.scala +++ b/test/files/neg/t0764b.scala @@ -1,3 +1,5 @@ +// see neg/t0764 why this should probably be a pos/ test -- alas something's wrong with existential subtyping (?) + // In all cases when calling "prepend" the receiver 'v' // has static type NodeAlias[A] or (equivalently) Node { type T = A }. // Since prepend explicitly returns the singleton type of the receiver, diff --git a/test/files/neg/t8104/Test_2.scala b/test/files/neg/t8104/Test_2.scala index 585f76c00f..a3bd940188 100644 --- a/test/files/neg/t8104/Test_2.scala +++ b/test/files/neg/t8104/Test_2.scala @@ -9,7 +9,7 @@ object Test extends App { case class C(x: Int, y: Int) import scala.reflect.runtime.universe._ - def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = println(tag) reprify(C(40, 2)) // this is a compilation error at the moment as explained in SI-8104 diff --git a/test/files/neg/t8177a.check b/test/files/neg/t8177a.check new file mode 100644 index 0000000000..0d01206e0c --- /dev/null +++ b/test/files/neg/t8177a.check @@ -0,0 +1,6 @@ +t8177a.scala:5: error: type mismatch; + found : A{type Result = Int} + required: A{type Result = String} + : A { type Result = String} = x + ^ +one error found diff --git a/test/files/neg/t8177a.scala b/test/files/neg/t8177a.scala new file mode 100644 index 0000000000..d1e47f8c1e --- /dev/null +++ b/test/files/neg/t8177a.scala @@ -0,0 +1,6 @@ +trait A { type Result } + +class PolyTests { + def wrong(x: A { type Result = Int }) + : A { type Result = String} = x +}
\ No newline at end of file diff --git a/test/files/pos/t0764.scala b/test/files/pos/t0764.scala deleted file mode 100644 index f1084f5ff8..0000000000 --- a/test/files/pos/t0764.scala +++ /dev/null @@ -1,27 +0,0 @@ -class Top[A] { - type AType = A -} - -trait Node { outer => - type T <: Node - def prepend = new Node { type T = outer.type } -} - -class Main[NextType <: Node](value: Node { type T = NextType }) - extends Top[Node { type T = NextType }] { - - new Main[AType]( (value: AType).prepend ) -} - -/* this used to be a neg test, even though it should've compiled -SI-8177 fixed this. - -Behold the equivalent program which type checks without the fix for SI-8177. -(Expand type alias, convert type member to type param; -note the covariance to encode subtyping on type members.) - -class Node[+T <: Node[_]] { def prepend = new Node[this.type] } -class Main[NextType <: Node[_]](value: Node[NextType]) { - new Main(value.prepend) -} -*/
\ No newline at end of file diff --git a/test/files/pos/t8177h.scala b/test/files/pos/t8177h.scala new file mode 100644 index 0000000000..90b8a26ce7 --- /dev/null +++ b/test/files/pos/t8177h.scala @@ -0,0 +1,5 @@ +class Module { self => + type settingsType <: Any + final type commonModuleType = Module {type settingsType = self.settingsType} + def foo(s: self.type): commonModuleType = s +} diff --git a/test/files/run/t6632.check b/test/files/run/t6632.check index 1f084b1dac..26cf061b5f 100644 --- a/test/files/run/t6632.check +++ b/test/files/run/t6632.check @@ -1,3 +1,5 @@ java.lang.IndexOutOfBoundsException: -1 java.lang.IndexOutOfBoundsException: -2 java.lang.IndexOutOfBoundsException: -3 +java.lang.IndexOutOfBoundsException: -1 +java.lang.IndexOutOfBoundsException: 5 diff --git a/test/files/run/t6632.scala b/test/files/run/t6632.scala index 0242e60104..f338b73fa6 100644 --- a/test/files/run/t6632.scala +++ b/test/files/run/t6632.scala @@ -3,27 +3,20 @@ object Test extends App { def newLB = ListBuffer('a, 'b, 'c, 'd, 'e) - val lb0 = newLB + def iiobe[A](f: => A) = + try { f } + catch { case ex: IndexOutOfBoundsException => println(ex) } - try { - lb0.insert(-1, 'x) - } catch { - case ex: IndexOutOfBoundsException => println(ex) - } + val lb0 = newLB + iiobe( lb0.insert(-1, 'x) ) val lb1 = newLB - - try { - lb1.insertAll(-2, Array('x, 'y, 'z)) - } catch { - case ex: IndexOutOfBoundsException => println(ex) - } + iiobe( lb1.insertAll(-2, Array('x, 'y, 'z)) ) val lb2 = newLB + iiobe( lb2.update(-3, 'u) ) - try { - lb2.update(-3, 'u) - } catch { - case ex: IndexOutOfBoundsException => println(ex) - } -}
\ No newline at end of file + val lb3 = newLB + iiobe( lb3.updated(-1, 'u) ) + iiobe( lb3.updated(5, 'u) ) +} diff --git a/test/files/run/t6992.check b/test/files/run/t6992.check index 1a0684c995..021f32ec95 100644 --- a/test/files/run/t6992.check +++ b/test/files/run/t6992.check @@ -1,3 +1,4 @@ +Test.foo.T Int 42 42 diff --git a/test/files/run/t6992/Test_2.scala b/test/files/run/t6992/Test_2.scala index 05282d6f5b..1ed8958d38 100644 --- a/test/files/run/t6992/Test_2.scala +++ b/test/files/run/t6992/Test_2.scala @@ -2,7 +2,9 @@ import scala.language.reflectiveCalls object Test extends App { val foo = Macros.foo("T") - println(scala.reflect.runtime.universe.weakTypeOf[foo.T].typeSymbol.typeSignature) + val ttpe = scala.reflect.runtime.universe.weakTypeOf[foo.T] + println(ttpe) + println(ttpe.typeSymbol.typeSignature) val bar = Macros.bar("test") println(bar.test) diff --git a/test/files/run/t8104.check b/test/files/run/t8104.check index c2593eb199..40523a2868 100644 --- a/test/files/run/t8104.check +++ b/test/files/run/t8104.check @@ -1 +1,2 @@ -TypeTag[(Int, Int)] +WeakTypeTag[<refinement>.this.Repr] +(Int, Int) diff --git a/test/files/run/t8104/Test_2.scala b/test/files/run/t8104/Test_2.scala index 630176f175..55c080a563 100644 --- a/test/files/run/t8104/Test_2.scala +++ b/test/files/run/t8104/Test_2.scala @@ -9,7 +9,10 @@ object Test extends App { case class C(x: Int, y: Int) import scala.reflect.runtime.universe._ - def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: TypeTag[Repr]) = println(tag) + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = { + println(tag) + println(tag.tpe.typeSymbol.typeSignature) + } reprify(C(40, 2)) implicitly[Generic.Aux[C, (Int, Int)]] diff --git a/test/files/run/t8153.check b/test/files/run/t8153.check new file mode 100644 index 0000000000..0cfbf08886 --- /dev/null +++ b/test/files/run/t8153.check @@ -0,0 +1 @@ +2 diff --git a/test/files/run/t8153.scala b/test/files/run/t8153.scala new file mode 100644 index 0000000000..f9b223f974 --- /dev/null +++ b/test/files/run/t8153.scala @@ -0,0 +1,14 @@ +object Test { + def f() = { + val lb = scala.collection.mutable.ListBuffer[Int](1, 2) + val it = lb.iterator + if (it.hasNext) it.next + val xs = lb.toList + lb += 3 + it.mkString + } + + def main(args: Array[String]) { + println(f()) + } +} diff --git a/test/files/run/t8188.scala b/test/files/run/t8188.scala new file mode 100644 index 0000000000..ec3a968e4a --- /dev/null +++ b/test/files/run/t8188.scala @@ -0,0 +1,25 @@ +object Test { + def main(args: Array[String]) { + import java.io.ByteArrayInputStream + import java.io.ByteArrayOutputStream + import java.io.ObjectInputStream + import java.io.ObjectOutputStream + import scala.collection.concurrent.TrieMap + + def ser[T](o: T): Array[Byte] = { + val baos = new ByteArrayOutputStream() + new ObjectOutputStream(baos).writeObject(o) + baos.toByteArray() + } + + def deser[T](bs: Array[Byte]): T = + new ObjectInputStream(new ByteArrayInputStream(bs)).readObject().asInstanceOf[T] + + def cloneViaSerialization[T](t: T): T = deser(ser(t)) + + val f = cloneViaSerialization(_: TrieMap[Int, Int]) + val tm = TrieMap(1 -> 2) + assert( f(f(tm)) == tm ) + assert( ser(tm).length == ser(f(tm)).length ) + } +} |