diff options
author | Martin Odersky <odersky@gmail.com> | 2016-01-31 14:03:26 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-02-09 09:43:05 +0100 |
commit | 9a6f82b2ecfd7462d0a1f4e0464878fd58231277 (patch) | |
tree | 8e9e46b08d7fdf45f4b1fd06b30d7e35c43f05b1 /tests/pos-scala2 | |
parent | 44c14b3fb6e5eb6f2b9734f092eef1d85f6b4d18 (diff) | |
download | dotty-9a6f82b2ecfd7462d0a1f4e0464878fd58231277.tar.gz dotty-9a6f82b2ecfd7462d0a1f4e0464878fd58231277.tar.bz2 dotty-9a6f82b2ecfd7462d0a1f4e0464878fd58231277.zip |
Reorganize tests to account for new typing of projection
Tests with failed projections are moved to pos-scala2, which
was renamed from pos-special. Files in pos-scala2 are compiled
with -language:Scala2 option.
Diffstat (limited to 'tests/pos-scala2')
-rw-r--r-- | tests/pos-scala2/i871.scala | 4 | ||||
-rw-r--r-- | tests/pos-scala2/t1292.scala | 32 | ||||
-rw-r--r-- | tests/pos-scala2/t2994.scala | 35 | ||||
-rw-r--r-- | tests/pos-scala2/t3568.scala | 46 | ||||
-rw-r--r-- | tests/pos-scala2/t3731.scala | 13 | ||||
-rw-r--r-- | tests/pos-scala2/t3833.scala | 26 | ||||
-rw-r--r-- | tests/pos-scala2/t5070.scala | 18 | ||||
-rw-r--r-- | tests/pos-scala2/t5541.scala | 61 | ||||
-rw-r--r-- | tests/pos-scala2/variances-constr.scala | 27 |
9 files changed, 262 insertions, 0 deletions
diff --git a/tests/pos-scala2/i871.scala b/tests/pos-scala2/i871.scala new file mode 100644 index 000000000..2e5f100d8 --- /dev/null +++ b/tests/pos-scala2/i871.scala @@ -0,0 +1,4 @@ +trait Message { + def first(x: Int) + def second +} diff --git a/tests/pos-scala2/t1292.scala b/tests/pos-scala2/t1292.scala new file mode 100644 index 000000000..8e69734e9 --- /dev/null +++ b/tests/pos-scala2/t1292.scala @@ -0,0 +1,32 @@ +trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] { + type StV = Enum#Value + type Meta = MegaFoo[T, Enum] + + type Slog = Enumeration + + def getSingleton: Meta +} + +trait MegaFoo[T <: Foo[T, Enum], Enum <: Enumeration] extends Foo[T, Enum] { + def doSomething(what: T, misc: StV, dog: Meta#Event) = None + + abstract class Event + object Event + + def stateEnumeration: Slog + def se2: Enum +} + +object E extends Enumeration { + val A = Value + val B = Value +} + +class RFoo extends Foo[RFoo, E.type] { + def getSingleton = MegaRFoo +} + +object MegaRFoo extends RFoo with MegaFoo[RFoo, E.type] { + def stateEnumeration = E + def se2 = E +} diff --git a/tests/pos-scala2/t2994.scala b/tests/pos-scala2/t2994.scala new file mode 100644 index 000000000..c7421c42a --- /dev/null +++ b/tests/pos-scala2/t2994.scala @@ -0,0 +1,35 @@ +object Naturals { + trait NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] <: NAT + type v = a[SUCC, ZERO] + } + final class ZERO extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = z + } + final class SUCC[n <: NAT] extends NAT { + type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] + } + type _0 = ZERO + type _1 = SUCC[_0] + type _2 = SUCC[_1] + type _3 = SUCC[_2] + type _4 = SUCC[_3] + type _5 = SUCC[_4] + type _6 = SUCC[_5] + + + // crashes scala-2.8.0 beta1 + trait MUL[n <: NAT, m <: NAT] extends NAT { + trait curry[n[_, _], s[_]] { type f[z <: NAT] = n[s, z] } + type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] + } + +} + +object Test { + trait Bar[X[_]] + trait Baz[S[_] <: Bar[S]] { + type Apply[T] + } + trait Foo[V[_] <: Bar[V]] extends Bar[Baz[V]#Apply] +} diff --git a/tests/pos-scala2/t3568.scala b/tests/pos-scala2/t3568.scala new file mode 100644 index 000000000..50f0cdb2e --- /dev/null +++ b/tests/pos-scala2/t3568.scala @@ -0,0 +1,46 @@ +import scala.annotation._ +import scala.annotation.unchecked._ +import scala.collection._ + + +package object buffer { + val broken = new ArrayVec2() // commenting out this line causes the file to compile. + + val works = Class.forName("buffer.ArrayVec2").newInstance().asInstanceOf[ArrayVec2] +} + +package buffer { + object Main { + // ArrayVec2 can be compiled, instantiated and used. + def main(args: Array[String]): Unit = { println(works) } + } + + trait ElemType { type Element; type Component <: ElemType } + trait Float1 extends ElemType { type Element = Float; type Component = Float1} + class Vec2 extends ElemType { type Element = Vec2; type Component = Float1 } + + abstract class BaseSeq[T <: ElemType, E] + extends IndexedSeq[E] with IndexedSeqOptimized[E, IndexedSeq[E]] { + def length = 1 + def apply(i: Int) :E + } + + abstract class GenericSeq[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataArray[T <: ElemType] extends BaseSeq[T, T#Element] + trait DataView[T <: ElemType] extends BaseSeq[T, T#Element] + abstract class BaseFloat1 extends BaseSeq[Float1, Float] + + class ArrayFloat1 extends BaseFloat1 with DataArray[Float1] { + def apply(i: Int) :Float = 0f + } + + class ViewFloat1 extends BaseFloat1 with DataView[Float1] { + def apply(i: Int) :Float = 0f + } + + class ArrayVec2(val backingSeq: ArrayFloat1) + extends GenericSeq[Vec2] with DataArray[Vec2] { + def this() = this(new ArrayFloat1) + def apply(i: Int) :Vec2 = null + } +} diff --git a/tests/pos-scala2/t3731.scala b/tests/pos-scala2/t3731.scala new file mode 100644 index 000000000..7a3cbec0f --- /dev/null +++ b/tests/pos-scala2/t3731.scala @@ -0,0 +1,13 @@ +object Test{ + trait ZW[S]{type T} + def ZipWith[S, M <: ZW[S]]: M#T = sys.error("ZW") + + // meh must be parameterised to force an asSeenFrom that + // duplicates the refinement in the TR's pre without updating its sym + def meh[A] = ZipWith[A, ZW[A]{type T=Stream[A]}] + + meh[Int]: Stream[Int] +} +// debugging output in coevolveSym should say: +// coevolved type T#11029 : Stream#3234[A#9228] to type T#11277 : Stream#3234[A#9227] +// with Test.ZW#9219[A#9228]{type T#11029 = Stream#3234[A#9228]} -> Test.ZW#9219[A#9227]{type T#11277 = Stream#3234[A#9227]} diff --git a/tests/pos-scala2/t3833.scala b/tests/pos-scala2/t3833.scala new file mode 100644 index 000000000..2df658df1 --- /dev/null +++ b/tests/pos-scala2/t3833.scala @@ -0,0 +1,26 @@ +object Main { + def mkArray[T <: A](atype: Int) :T#AType = { + (atype match { + case 1 => + new Array[Int](10) + // Decompiled code: return (Object[])new int[10]; + case 2 => + new Array[Float](10) + }).asInstanceOf[T#AType] + } + + def main(args: Array[String]): Unit = { + println(mkArray[I](1)) + //java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object; + } +} + +trait A { + type AType <: AnyRef +} +trait I extends A { + type AType = Array[Int] +} +trait F extends A { + type AType = Array[Float] +} diff --git a/tests/pos-scala2/t5070.scala b/tests/pos-scala2/t5070.scala new file mode 100644 index 000000000..c236b4f9e --- /dev/null +++ b/tests/pos-scala2/t5070.scala @@ -0,0 +1,18 @@ +trait Web { + type LocalName +} +trait Companion1[A] +trait WebDSL[W <: Web] { + trait LocalNameCompanion extends Companion1[W#LocalName] { + type A = String + } + implicit val LocalName: LocalNameCompanion +} +object Test { + def t[W <: Web](implicit webDSL: WebDSL[W]): Unit = { + import webDSL._ + implicitly[LocalNameCompanion] // succeeds + implicitly[Companion1[W#LocalName]] // fails + } +} + diff --git a/tests/pos-scala2/t5541.scala b/tests/pos-scala2/t5541.scala new file mode 100644 index 000000000..54e2b6518 --- /dev/null +++ b/tests/pos-scala2/t5541.scala @@ -0,0 +1,61 @@ +package philips.adolf.paul + +trait Sys[ S <: Sys[ S ]] { + type Tx +} + +object HASkipList { + sealed trait NodeLike[ S <: Sys[ S ], @specialized( Int ) A ] { + def size : Int + def key( i: Int ): A + } + sealed trait Node[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def isLeaf : Boolean + def isBranch : Boolean + def asBranch : Branch[ S, A ] + } + sealed trait BranchLike[ S <: Sys[ S ], @specialized( Int ) A ] extends NodeLike[ S, A ] { + def down( i: Int )( implicit tx: S#Tx ) : Node[ S, A ] = sys.error("") + } + sealed trait HeadOrBranch[ S <: Sys[ S ], A ] + final class Branch[ S <: Sys[ S ], @specialized( Int ) A ]() + extends BranchLike[ S, A ] with HeadOrBranch[ S, A ] with Node[ S, A ] { + def size:Int=1234 + def key(i: Int):A=sys.error("TODO") + def isLeaf : Boolean = false + def isBranch : Boolean = true + def asBranch : Branch[ S, A ] = this + } +} +sealed trait HASkipList[ S <: Sys[ S ], @specialized( Int ) A ] + +class HASkipListView[ S <: Sys[ S ], A ]( private val l: HASkipList[ S, A ])( implicit system: S ) { + import HASkipList.Node + private def buildBoxMap( n: Node[ S, A ], isRight: Boolean )( implicit tx: S#Tx ) : (Box, NodeBox) = { + val sz = n.size + val szm = sz - 1 + val keys = IndexedSeq.tabulate( sz ) { i => + val key = n.key( i ) + (key, if ( isRight && i == szm ) "M" else key.toString) + } + val chbo = if ( n.isLeaf ) None else { + val nb = n.asBranch + Some( IndexedSeq.tabulate( sz )( i => buildBoxMap( nb.down( i ), isRight && (i == szm) ))) + } + val b = NodeBox( n, keys, chbo.map( _.map( _._2 ))) + val bb = chbo match { + case Some( chbt ) => + val chb = chbt.map( _._1 ) + val h = Horiz( bs = chb ) + Vert( bs = IndexedSeq[Box]( b, h )) + case None => b + } + + (bb, b) + } + + private trait Box + private case class Horiz( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class Vert( spacing: Int = 20, bs: IndexedSeq[ Box ]) extends Box + private final case class NodeBox( n: Node[ S, A ], keys: IndexedSeq[ (A, String) ], downs: Option[ IndexedSeq[ NodeBox ]]) extends Box +} diff --git a/tests/pos-scala2/variances-constr.scala b/tests/pos-scala2/variances-constr.scala new file mode 100644 index 000000000..ee4219b10 --- /dev/null +++ b/tests/pos-scala2/variances-constr.scala @@ -0,0 +1,27 @@ +class C[+A] { + + private[this] var y: A = _ + def getY: A = y + + class Inner(x: A) { + y = x + } +} + +object Test { + + def main(args: Array[String]) = { + val x = new C[String] + val y: C[Any] = x + val i = new y.Inner(1) + val s: String = x.getY + println(s) + } +} + +class CC[+A] { + class Inner { + def this(a: A) = this() + } +} + |