diff options
author | Martin Odersky <odersky@gmail.com> | 2015-12-20 22:00:29 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-12-20 22:00:45 +0100 |
commit | e51b8845fb20fe3a4e1c655d4b72e2833906bbc2 (patch) | |
tree | 91bc16867d7a709566d8be80902b3256294cf338 /tests/invalid/pos/IterableSelfRec.scala | |
parent | 581fee04f808d6f7759f98358e7475e6a58138e3 (diff) | |
download | dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.tar.gz dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.tar.bz2 dotty-e51b8845fb20fe3a4e1c655d4b72e2833906bbc2.zip |
The big pending/pos test triage
Diffstat (limited to 'tests/invalid/pos/IterableSelfRec.scala')
-rw-r--r-- | tests/invalid/pos/IterableSelfRec.scala | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/invalid/pos/IterableSelfRec.scala b/tests/invalid/pos/IterableSelfRec.scala new file mode 100644 index 000000000..7fd235f12 --- /dev/null +++ b/tests/invalid/pos/IterableSelfRec.scala @@ -0,0 +1,53 @@ +// This does not currently work because it mixes higher-kinded types and raw type constructors. +package dotty.collection +package immutable + +import annotation.unchecked.uncheckedVariance + +trait Collection[T] { self => + type This <: Collection { type This <: self.This } + def companion: CollectionCompanion[This] +} + +trait Iterable[T] extends Collection[T] { self => + type This <: Iterable { type This <: self.This } + override def companion: IterableCompanion[This] = Iterable.asInstanceOf + + def iterator: Iterator[T] +} + +trait Seq[T] extends Iterable[T] { self => + type This <: Seq { type This <: self.This } + override def companion: IterableCompanion[This] = Seq.asInstanceOf + + def apply(x: Int): T +} + +abstract class CollectionCompanion[+CC[X] <: Collection[X] { type This <: CC }] + +abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] extends CollectionCompanion[CC] { + def fromIterator[T](it: Iterator[T]): CC[T] + def map[T, U](xs: Iterable[T], f: T => U): CC[U] = + fromIterator(xs.iterator.map(f)) + def filter[T](xs: Iterable[T], p: T => Boolean): CC[T] = + fromIterator(xs.iterator.filter(p)) + def flatMap[T, U](xs: Iterable[T], f: T => TraversableOnce[U]): CC[U] = + fromIterator(xs.iterator.flatMap(f)) + + implicit def transformOps[T](xs: CC[T] @uncheckedVariance): TransformOps[CC, T] = ??? // new TransformOps[CC, T](xs) +} + +class TransformOps[+CC[X] <: Iterable[X] { type This <: CC }, T] (val xs: CC[T]) extends AnyVal { + def companion[T](xs: CC[T] @uncheckedVariance): IterableCompanion[CC] = xs.companion + def map[U](f: T => U): CC[U] = companion(xs).map(xs, f) + def filter(p: T => Boolean): CC[T] = companion(xs).filter(xs, p) + def flatMap[U](f: T => TraversableOnce[U]): CC[U] = companion(xs).flatMap(xs, f) +} + +object Iterable extends IterableCompanion[Iterable] { + def fromIterator[T](it: Iterator[T]): Iterable[T] = ??? +} +object Seq extends IterableCompanion[Seq] { + def fromIterator[T](it: Iterator[T]): Seq[T] = ??? +} + |