From ed1d5f310951715d95873c56f64195ac3ee45817 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 13 May 2014 17:03:36 +0200 Subject: Fix of pos/t2454 "_" type paraeters need to be given fresh names. --- src/dotty/tools/dotc/parsing/Parsers.scala | 11 +++++---- tests/new/t2405.scala | 23 ------------------ tests/new/t2421.scala | 14 ----------- tests/new/t2421_delitedsl.scala | 39 ------------------------------ tests/new/t2421b_pos.scala | 19 --------------- tests/new/t2421c.scala | 17 ------------- tests/new/t2425.scala | 15 ------------ tests/new/t2435.scala | 27 --------------------- tests/new/t2441pos.scala | 8 ------ tests/new/t2444.scala | 15 ------------ tests/new/t245.scala | 18 -------------- tests/new/t247.scala | 26 -------------------- tests/new/t2484.scala | 19 --------------- tests/new/t2486.scala | 3 --- tests/pending/pos/t2454.scala | 25 ------------------- tests/pos/t2405.scala | 23 ++++++++++++++++++ tests/pos/t2421.scala | 14 +++++++++++ tests/pos/t2421_delitedsl.scala | 39 ++++++++++++++++++++++++++++++ tests/pos/t2421b_pos.scala | 19 +++++++++++++++ tests/pos/t2421c.scala | 17 +++++++++++++ tests/pos/t2425.scala | 15 ++++++++++++ tests/pos/t2435.scala | 27 +++++++++++++++++++++ tests/pos/t2441pos.scala | 8 ++++++ tests/pos/t2444.scala | 15 ++++++++++++ tests/pos/t245.scala | 18 ++++++++++++++ tests/pos/t2454.scala | 25 +++++++++++++++++++ tests/pos/t247.scala | 26 ++++++++++++++++++++ tests/pos/t2484.scala | 19 +++++++++++++++ tests/pos/t2486.scala | 3 +++ 29 files changed, 274 insertions(+), 273 deletions(-) delete mode 100644 tests/new/t2405.scala delete mode 100644 tests/new/t2421.scala delete mode 100644 tests/new/t2421_delitedsl.scala delete mode 100644 tests/new/t2421b_pos.scala delete mode 100644 tests/new/t2421c.scala delete mode 100755 tests/new/t2425.scala delete mode 100644 tests/new/t2435.scala delete mode 100644 tests/new/t2441pos.scala delete mode 100644 tests/new/t2444.scala delete mode 100644 tests/new/t245.scala delete mode 100644 tests/new/t247.scala delete mode 100755 tests/new/t2484.scala delete mode 100644 tests/new/t2486.scala delete mode 100644 tests/pending/pos/t2454.scala create mode 100644 tests/pos/t2405.scala create mode 100644 tests/pos/t2421.scala create mode 100644 tests/pos/t2421_delitedsl.scala create mode 100644 tests/pos/t2421b_pos.scala create mode 100644 tests/pos/t2421c.scala create mode 100755 tests/pos/t2425.scala create mode 100644 tests/pos/t2435.scala create mode 100644 tests/pos/t2441pos.scala create mode 100644 tests/pos/t2444.scala create mode 100644 tests/pos/t245.scala create mode 100644 tests/pos/t2454.scala create mode 100644 tests/pos/t247.scala create mode 100755 tests/pos/t2484.scala create mode 100644 tests/pos/t2486.scala diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index 7bc7d5516..0ad33a96c 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -447,10 +447,6 @@ object Parsers { if (tok == BACKQUOTED_IDENT) BackquotedIdent(name) else Ident(name) - /** IdentOrWildcard ::= id | `_' */ - def identOrWildcard(): Name = - if (in.token == USCORE) { in.nextToken(); nme.WILDCARD } else ident() - def wildcardIdent(): Ident = atPos(accept(USCORE)) { Ident(nme.WILDCARD) } @@ -1478,7 +1474,12 @@ object Parsers { if (mods is VarianceFlags) in.nextToken() } atPos(tokenRange) { - val name = (if (isConcreteOwner) ident() else identOrWildcard()).toTypeName + val name = + if (isConcreteOwner || in.token != USCORE) ident().toTypeName + else { + in.nextToken() + ctx.freshName(nme.USCORE_PARAM_PREFIX).toTypeName + } val hkparams = if (ownerKind == ParamOwner.TypeParam) Nil else typeParamClauseOpt(ParamOwner.TypeParam) diff --git a/tests/new/t2405.scala b/tests/new/t2405.scala deleted file mode 100644 index 224b2ce83..000000000 --- a/tests/new/t2405.scala +++ /dev/null @@ -1,23 +0,0 @@ -object A { implicit val x: Int = 1 } - -// Problem as stated in the ticket. -object Test1 { - import A.{x => y} - implicitly[Int] -} - -// Testing for the absense of shadowing #1. -object Test2 { - import A.{x => y} - val x = 2 - implicitly[Int] -} - -// Testing for the absense of shadowing #2. -object Test3 { - { - import A.{x => y} - def x: Int = 0 - implicitly[Int] - } -} diff --git a/tests/new/t2421.scala b/tests/new/t2421.scala deleted file mode 100644 index 2544a1cb3..000000000 --- a/tests/new/t2421.scala +++ /dev/null @@ -1,14 +0,0 @@ -object Test { - abstract class <~<[-From, +To] extends (From => To) - implicit def trivial[A]: A <~< A = sys.error("") - - - trait Forcible[T] - implicit val forcibleInt: (Int <~< Forcible[Int]) = sys.error("") - - def headProxy[P <: Forcible[Int]](implicit w: Int <~< P): P = sys.error("") - - headProxy - // trivial[Int] should not be considered a valid implicit, since w would have type Int <~< Int, - // and headProxy's type parameter P cannot be instantiated to Int -} diff --git a/tests/new/t2421_delitedsl.scala b/tests/new/t2421_delitedsl.scala deleted file mode 100644 index 554702a03..000000000 --- a/tests/new/t2421_delitedsl.scala +++ /dev/null @@ -1,39 +0,0 @@ -trait DeliteDSL { - abstract class <~<[-From, +To] extends (From => To) - implicit def trivial[A]: A <~< A = new (A <~< A) {def apply(x: A) = x} - - trait Forcible[T] - object Forcible { - def factory[T](f: T => Forcible[T]) = new (T <~< Forcible[T]){def apply(x: T) = f(x)} - } - - case class DeliteInt(x: Int) extends Forcible[Int] - - implicit val forcibleInt: DeliteDSL.this.<~<[Int,DeliteDSL.this.Forcible[Int]] = - Forcible.factory((x: Int) => DeliteInt(x)) - - import scala.collection.Traversable - class DeliteCollection[T](val xs: Traversable[T]) { - // must use existential in bound of P, instead of T itself, because we cannot both have: - // Test.x below: DeliteCollection[T=Int] -> P=DeliteInt <: Forcible[T=Int], as T=Int <~< P=DeliteInt - // Test.xAlready below: DeliteCollection[T=DeliteInt] -> P=DeliteInt <: Forcible[T=DeliteInt], as T=DeliteInt <~< P=DeliteInt - // this would required DeliteInt <: Forcible[Int] with Forcible[DeliteInt] - - def headProxy[P <: Forcible[_]](implicit w: T <~< P): P = xs.head - } - // If T is already a proxy (it is forcible), the compiler should use - // forcibleIdentity to deduce that P=T. If T is Int, the compiler - // should use intToForcible to deduce that P=DeliteInt. - // - // Without this feature, the user must write 'xs.proxyOfFirst[DeliteInt]', - // with the feature they can write 'xs.proxyOfFirst', which is shorter and - // avoids exposing internal DELITE types to the world. - - object Test { - val x = new DeliteCollection(List(1,2,3)).headProxy - // inferred: val x: Forcible[Int] = new DeliteCollection[Int](List.apply[Int](1, 2, 3)).headProxy[Forcible[Int]](forcibleInt); - - val xAlready = new DeliteCollection(List(DeliteInt(1),DeliteInt(2),DeliteInt(3))).headProxy - // inferred: val xAlready: DeliteInt = new DeliteCollection[DeliteInt](List.apply[DeliteInt](DeliteInt(1), DeliteInt(2), DeliteInt(3))).headProxy[DeliteInt](trivial[DeliteInt]); - } -} diff --git a/tests/new/t2421b_pos.scala b/tests/new/t2421b_pos.scala deleted file mode 100644 index 679b8a8d6..000000000 --- a/tests/new/t2421b_pos.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Test { - class A - class B - class C - class F[X] - - def f(implicit aa: F[A]) = println(aa) - - implicit def a : F[A] = new F[A]() - implicit def b[X <: B]: Test.F[X] = new F[X]() - - f -} -/* bug: -error: ambiguous implicit values: - both method b in object Test1 of type [X <: Test1.B]Test1.F[X] - and method a in object Test1 of type => Test1.F[Test1.A] - match expected type Test1.F[Test1.A] -*/ diff --git a/tests/new/t2421c.scala b/tests/new/t2421c.scala deleted file mode 100644 index bd24cacd7..000000000 --- a/tests/new/t2421c.scala +++ /dev/null @@ -1,17 +0,0 @@ -object Test { - class A - class B - class C - class F[X] - - def f(implicit aa: F[A]) = println(aa) - - implicit def a : F[A] = new F[A]() - - // generalised from t2421b to verify we check enough - class G[X] - implicit def g[X]: Test.G[X] = new G[X]() - implicit def b[X <: B](implicit mx: G[X]): Test.F[X] = new F[X]() - - f -} diff --git a/tests/new/t2425.scala b/tests/new/t2425.scala deleted file mode 100755 index 477d5467a..000000000 --- a/tests/new/t2425.scala +++ /dev/null @@ -1,15 +0,0 @@ -trait B -class D extends B -object Test extends App { - def foo[T](bar: T) = { - bar match { - case _: Array[Array[_]] => println("array 2d") - case _: Array[_] => println("array 1d") - case _ => println("something else") - } - } - foo(Array.fill(10)(2)) - foo(Array.fill(10, 10)(2)) - foo(Array.fill(10, 10, 10)(2)) - foo(List(1, 2, 3)) -} diff --git a/tests/new/t2435.scala b/tests/new/t2435.scala deleted file mode 100644 index 697e9e1f2..000000000 --- a/tests/new/t2435.scala +++ /dev/null @@ -1,27 +0,0 @@ -object Bug { - abstract class FChain { - type T - - def chain(constant:String) = - new FConstant[this.type](constant, this) //removing [this.type], everything compiles - } - - case class FConstant[E <: FChain](constant:String, tail:E) extends FChain { - type T = tail.T - } - - object FNil extends FChain { - type T = Unit - } - -} - -object Test { - import Bug._ - println("Compiles:") - val a1 = FNil.chain("a").chain("a") - val a2 = a1.chain("a") - - println("\nDoesn't compile:") - val a = FNil.chain("a").chain("a").chain("a") -} diff --git a/tests/new/t2441pos.scala b/tests/new/t2441pos.scala deleted file mode 100644 index 25eb2232c..000000000 --- a/tests/new/t2441pos.scala +++ /dev/null @@ -1,8 +0,0 @@ -abstract class A { - private def foo = List(1, 2) -} -trait B extends A { - private def foo = List("a", "b") - // However it compiles correctly if the type is given: - // private def foo: List[String] = List("a", "b") -} diff --git a/tests/new/t2444.scala b/tests/new/t2444.scala deleted file mode 100644 index fac1e95d0..000000000 --- a/tests/new/t2444.scala +++ /dev/null @@ -1,15 +0,0 @@ -object Test { - - trait Foo - - class Bar { - object baz extends Foo - } - - def frob[P1, P2<:Foo](f:P1 => P2) = () - - def main(args:Array[String]) : Unit = { - frob((p:Bar) => p.baz) - } - -} diff --git a/tests/new/t245.scala b/tests/new/t245.scala deleted file mode 100644 index 570ac4178..000000000 --- a/tests/new/t245.scala +++ /dev/null @@ -1,18 +0,0 @@ -class Value {} - -object Test { - - implicit def view(v: Value): Int = 0 - - def foo(i: Int): Int = 0 - - def fun0 : Value = null - def fun0(i: Int ): Value = null - - def fun1(i: Int ): Value = null - def fun1(l: Long): Value = null - - foo(fun0 ); - foo(fun1(new Value)); - -} diff --git a/tests/new/t247.scala b/tests/new/t247.scala deleted file mode 100644 index fdcafeb2c..000000000 --- a/tests/new/t247.scala +++ /dev/null @@ -1,26 +0,0 @@ -class Order[t](less:(t,t) => Boolean,equal:(t,t) => Boolean) {} - -trait Map[A, B] extends scala.collection.Map[A, B] { - val factory:MapFactory[A] -} -abstract class MapFactory[A] { - def Empty[B]:Map[A,B]; -} - -class TreeMapFactory[KEY](newOrder:Order[KEY]) extends MapFactory[KEY] { - val order = newOrder; - def Empty[V] = new TreeMap[KEY,V](new TreeMapFactory[KEY](order)); -} - -class Tree[KEY,Entry](order:Order[KEY]) { - def size =0; -} - -class TreeMap[KEY,VALUE](_factory:TreeMapFactory[KEY]) extends Tree[KEY,Tuple2[KEY,VALUE]](_factory.order) with scala.collection.DefaultMap[KEY, VALUE] with Map[KEY, VALUE] { - val factory = _factory - val order = _factory.order; - def this(newOrder:Order[KEY]) = this(new TreeMapFactory[KEY](newOrder)); - def get(key:KEY) = null; - def iterator:Iterator[Tuple2[KEY,VALUE]] = null; - override def size = super[Tree].size -} diff --git a/tests/new/t2484.scala b/tests/new/t2484.scala deleted file mode 100755 index 15165c247..000000000 --- a/tests/new/t2484.scala +++ /dev/null @@ -1,19 +0,0 @@ -import concurrent.ExecutionContext.Implicits.global - -class Admin extends javax.swing.JApplet { - val jScrollPane = new javax.swing.JScrollPane (null, 0, 0) - def t2484: Unit = { - scala.concurrent.Future {jScrollPane.synchronized { - def someFunction () = {} - //scala.concurrent.ops.spawn {someFunction ()} - jScrollPane.addComponentListener (new java.awt.event.ComponentAdapter {override def componentShown (e: java.awt.event.ComponentEvent) = { - someFunction (); jScrollPane.removeComponentListener (this)}}) - }} - } -} -// t2630.scala -object Test { - def meh(xs: List[Any]): Unit = { - xs map { x => (new AnyRef {}) } - } -} diff --git a/tests/new/t2486.scala b/tests/new/t2486.scala deleted file mode 100644 index 69fe4c127..000000000 --- a/tests/new/t2486.scala +++ /dev/null @@ -1,3 +0,0 @@ -class A[T] -class B extends A[Int] -class C[T] extends A[T] { def f(t: A[T]) = t match { case x: B => () } } diff --git a/tests/pending/pos/t2454.scala b/tests/pending/pos/t2454.scala deleted file mode 100644 index 00f2e6f67..000000000 --- a/tests/pending/pos/t2454.scala +++ /dev/null @@ -1,25 +0,0 @@ -package am; - -trait One[M[_]] { - val x : Int -} - -trait Two[M[_,_]] { - val x : Int -} - -object Test { - // Works. - val x = new Two[Map] { - val x = 5 - } - - val o = new One[java.util.List] { - val x = 1 - } - - // Does not work - val y = new Two[java.util.concurrent.ConcurrentHashMap] { - val x = 3 - } -} diff --git a/tests/pos/t2405.scala b/tests/pos/t2405.scala new file mode 100644 index 000000000..224b2ce83 --- /dev/null +++ b/tests/pos/t2405.scala @@ -0,0 +1,23 @@ +object A { implicit val x: Int = 1 } + +// Problem as stated in the ticket. +object Test1 { + import A.{x => y} + implicitly[Int] +} + +// Testing for the absense of shadowing #1. +object Test2 { + import A.{x => y} + val x = 2 + implicitly[Int] +} + +// Testing for the absense of shadowing #2. +object Test3 { + { + import A.{x => y} + def x: Int = 0 + implicitly[Int] + } +} diff --git a/tests/pos/t2421.scala b/tests/pos/t2421.scala new file mode 100644 index 000000000..2544a1cb3 --- /dev/null +++ b/tests/pos/t2421.scala @@ -0,0 +1,14 @@ +object Test { + abstract class <~<[-From, +To] extends (From => To) + implicit def trivial[A]: A <~< A = sys.error("") + + + trait Forcible[T] + implicit val forcibleInt: (Int <~< Forcible[Int]) = sys.error("") + + def headProxy[P <: Forcible[Int]](implicit w: Int <~< P): P = sys.error("") + + headProxy + // trivial[Int] should not be considered a valid implicit, since w would have type Int <~< Int, + // and headProxy's type parameter P cannot be instantiated to Int +} diff --git a/tests/pos/t2421_delitedsl.scala b/tests/pos/t2421_delitedsl.scala new file mode 100644 index 000000000..554702a03 --- /dev/null +++ b/tests/pos/t2421_delitedsl.scala @@ -0,0 +1,39 @@ +trait DeliteDSL { + abstract class <~<[-From, +To] extends (From => To) + implicit def trivial[A]: A <~< A = new (A <~< A) {def apply(x: A) = x} + + trait Forcible[T] + object Forcible { + def factory[T](f: T => Forcible[T]) = new (T <~< Forcible[T]){def apply(x: T) = f(x)} + } + + case class DeliteInt(x: Int) extends Forcible[Int] + + implicit val forcibleInt: DeliteDSL.this.<~<[Int,DeliteDSL.this.Forcible[Int]] = + Forcible.factory((x: Int) => DeliteInt(x)) + + import scala.collection.Traversable + class DeliteCollection[T](val xs: Traversable[T]) { + // must use existential in bound of P, instead of T itself, because we cannot both have: + // Test.x below: DeliteCollection[T=Int] -> P=DeliteInt <: Forcible[T=Int], as T=Int <~< P=DeliteInt + // Test.xAlready below: DeliteCollection[T=DeliteInt] -> P=DeliteInt <: Forcible[T=DeliteInt], as T=DeliteInt <~< P=DeliteInt + // this would required DeliteInt <: Forcible[Int] with Forcible[DeliteInt] + + def headProxy[P <: Forcible[_]](implicit w: T <~< P): P = xs.head + } + // If T is already a proxy (it is forcible), the compiler should use + // forcibleIdentity to deduce that P=T. If T is Int, the compiler + // should use intToForcible to deduce that P=DeliteInt. + // + // Without this feature, the user must write 'xs.proxyOfFirst[DeliteInt]', + // with the feature they can write 'xs.proxyOfFirst', which is shorter and + // avoids exposing internal DELITE types to the world. + + object Test { + val x = new DeliteCollection(List(1,2,3)).headProxy + // inferred: val x: Forcible[Int] = new DeliteCollection[Int](List.apply[Int](1, 2, 3)).headProxy[Forcible[Int]](forcibleInt); + + val xAlready = new DeliteCollection(List(DeliteInt(1),DeliteInt(2),DeliteInt(3))).headProxy + // inferred: val xAlready: DeliteInt = new DeliteCollection[DeliteInt](List.apply[DeliteInt](DeliteInt(1), DeliteInt(2), DeliteInt(3))).headProxy[DeliteInt](trivial[DeliteInt]); + } +} diff --git a/tests/pos/t2421b_pos.scala b/tests/pos/t2421b_pos.scala new file mode 100644 index 000000000..679b8a8d6 --- /dev/null +++ b/tests/pos/t2421b_pos.scala @@ -0,0 +1,19 @@ +object Test { + class A + class B + class C + class F[X] + + def f(implicit aa: F[A]) = println(aa) + + implicit def a : F[A] = new F[A]() + implicit def b[X <: B]: Test.F[X] = new F[X]() + + f +} +/* bug: +error: ambiguous implicit values: + both method b in object Test1 of type [X <: Test1.B]Test1.F[X] + and method a in object Test1 of type => Test1.F[Test1.A] + match expected type Test1.F[Test1.A] +*/ diff --git a/tests/pos/t2421c.scala b/tests/pos/t2421c.scala new file mode 100644 index 000000000..bd24cacd7 --- /dev/null +++ b/tests/pos/t2421c.scala @@ -0,0 +1,17 @@ +object Test { + class A + class B + class C + class F[X] + + def f(implicit aa: F[A]) = println(aa) + + implicit def a : F[A] = new F[A]() + + // generalised from t2421b to verify we check enough + class G[X] + implicit def g[X]: Test.G[X] = new G[X]() + implicit def b[X <: B](implicit mx: G[X]): Test.F[X] = new F[X]() + + f +} diff --git a/tests/pos/t2425.scala b/tests/pos/t2425.scala new file mode 100755 index 000000000..477d5467a --- /dev/null +++ b/tests/pos/t2425.scala @@ -0,0 +1,15 @@ +trait B +class D extends B +object Test extends App { + def foo[T](bar: T) = { + bar match { + case _: Array[Array[_]] => println("array 2d") + case _: Array[_] => println("array 1d") + case _ => println("something else") + } + } + foo(Array.fill(10)(2)) + foo(Array.fill(10, 10)(2)) + foo(Array.fill(10, 10, 10)(2)) + foo(List(1, 2, 3)) +} diff --git a/tests/pos/t2435.scala b/tests/pos/t2435.scala new file mode 100644 index 000000000..697e9e1f2 --- /dev/null +++ b/tests/pos/t2435.scala @@ -0,0 +1,27 @@ +object Bug { + abstract class FChain { + type T + + def chain(constant:String) = + new FConstant[this.type](constant, this) //removing [this.type], everything compiles + } + + case class FConstant[E <: FChain](constant:String, tail:E) extends FChain { + type T = tail.T + } + + object FNil extends FChain { + type T = Unit + } + +} + +object Test { + import Bug._ + println("Compiles:") + val a1 = FNil.chain("a").chain("a") + val a2 = a1.chain("a") + + println("\nDoesn't compile:") + val a = FNil.chain("a").chain("a").chain("a") +} diff --git a/tests/pos/t2441pos.scala b/tests/pos/t2441pos.scala new file mode 100644 index 000000000..25eb2232c --- /dev/null +++ b/tests/pos/t2441pos.scala @@ -0,0 +1,8 @@ +abstract class A { + private def foo = List(1, 2) +} +trait B extends A { + private def foo = List("a", "b") + // However it compiles correctly if the type is given: + // private def foo: List[String] = List("a", "b") +} diff --git a/tests/pos/t2444.scala b/tests/pos/t2444.scala new file mode 100644 index 000000000..fac1e95d0 --- /dev/null +++ b/tests/pos/t2444.scala @@ -0,0 +1,15 @@ +object Test { + + trait Foo + + class Bar { + object baz extends Foo + } + + def frob[P1, P2<:Foo](f:P1 => P2) = () + + def main(args:Array[String]) : Unit = { + frob((p:Bar) => p.baz) + } + +} diff --git a/tests/pos/t245.scala b/tests/pos/t245.scala new file mode 100644 index 000000000..570ac4178 --- /dev/null +++ b/tests/pos/t245.scala @@ -0,0 +1,18 @@ +class Value {} + +object Test { + + implicit def view(v: Value): Int = 0 + + def foo(i: Int): Int = 0 + + def fun0 : Value = null + def fun0(i: Int ): Value = null + + def fun1(i: Int ): Value = null + def fun1(l: Long): Value = null + + foo(fun0 ); + foo(fun1(new Value)); + +} diff --git a/tests/pos/t2454.scala b/tests/pos/t2454.scala new file mode 100644 index 000000000..00f2e6f67 --- /dev/null +++ b/tests/pos/t2454.scala @@ -0,0 +1,25 @@ +package am; + +trait One[M[_]] { + val x : Int +} + +trait Two[M[_,_]] { + val x : Int +} + +object Test { + // Works. + val x = new Two[Map] { + val x = 5 + } + + val o = new One[java.util.List] { + val x = 1 + } + + // Does not work + val y = new Two[java.util.concurrent.ConcurrentHashMap] { + val x = 3 + } +} diff --git a/tests/pos/t247.scala b/tests/pos/t247.scala new file mode 100644 index 000000000..fdcafeb2c --- /dev/null +++ b/tests/pos/t247.scala @@ -0,0 +1,26 @@ +class Order[t](less:(t,t) => Boolean,equal:(t,t) => Boolean) {} + +trait Map[A, B] extends scala.collection.Map[A, B] { + val factory:MapFactory[A] +} +abstract class MapFactory[A] { + def Empty[B]:Map[A,B]; +} + +class TreeMapFactory[KEY](newOrder:Order[KEY]) extends MapFactory[KEY] { + val order = newOrder; + def Empty[V] = new TreeMap[KEY,V](new TreeMapFactory[KEY](order)); +} + +class Tree[KEY,Entry](order:Order[KEY]) { + def size =0; +} + +class TreeMap[KEY,VALUE](_factory:TreeMapFactory[KEY]) extends Tree[KEY,Tuple2[KEY,VALUE]](_factory.order) with scala.collection.DefaultMap[KEY, VALUE] with Map[KEY, VALUE] { + val factory = _factory + val order = _factory.order; + def this(newOrder:Order[KEY]) = this(new TreeMapFactory[KEY](newOrder)); + def get(key:KEY) = null; + def iterator:Iterator[Tuple2[KEY,VALUE]] = null; + override def size = super[Tree].size +} diff --git a/tests/pos/t2484.scala b/tests/pos/t2484.scala new file mode 100755 index 000000000..15165c247 --- /dev/null +++ b/tests/pos/t2484.scala @@ -0,0 +1,19 @@ +import concurrent.ExecutionContext.Implicits.global + +class Admin extends javax.swing.JApplet { + val jScrollPane = new javax.swing.JScrollPane (null, 0, 0) + def t2484: Unit = { + scala.concurrent.Future {jScrollPane.synchronized { + def someFunction () = {} + //scala.concurrent.ops.spawn {someFunction ()} + jScrollPane.addComponentListener (new java.awt.event.ComponentAdapter {override def componentShown (e: java.awt.event.ComponentEvent) = { + someFunction (); jScrollPane.removeComponentListener (this)}}) + }} + } +} +// t2630.scala +object Test { + def meh(xs: List[Any]): Unit = { + xs map { x => (new AnyRef {}) } + } +} diff --git a/tests/pos/t2486.scala b/tests/pos/t2486.scala new file mode 100644 index 000000000..69fe4c127 --- /dev/null +++ b/tests/pos/t2486.scala @@ -0,0 +1,3 @@ +class A[T] +class B extends A[Int] +class C[T] extends A[T] { def f(t: A[T]) = t match { case x: B => () } } -- cgit v1.2.3 From e57fa24b34ab1836160be67a153cbaba2ebc6691 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 10:10:04 +0200 Subject: Refinements in diagnostics 1) glb/lub's are reported to subtyping printer instead of typr 2) Null arguments of function protos are printed with their types (views sometimes are transformed into these). --- src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++-- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 8 ++++++-- src/dotty/tools/dotc/typer/ProtoTypes.scala | 8 +++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 6174f0915..415385719 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -860,7 +860,7 @@ class TypeComparer(initctx: Context) extends DotClass { } /** The greatest lower bound of two types */ - def glb(tp1: Type, tp2: Type): Type = /*>|>*/ ctx.traceIndented(s"glb(${tp1.show}, ${tp2.show})", typr, show = true) /*<|<*/ { + def glb(tp1: Type, tp2: Type): Type = /*>|>*/ ctx.traceIndented(s"glb(${tp1.show}, ${tp2.show})", subtyping, show = true) /*<|<*/ { if (tp1 eq tp2) tp1 else if (!tp1.exists) tp2 else if (!tp2.exists) tp1 @@ -892,7 +892,7 @@ class TypeComparer(initctx: Context) extends DotClass { /** The least upper bound of two types * @note We do not admit singleton types in or-types as lubs. */ - def lub(tp1: Type, tp2: Type): Type = /*>|>*/ ctx.traceIndented(s"lub(${tp1.show}, ${tp2.show})", typr, show = true) /*<|<*/ { + def lub(tp1: Type, tp2: Type): Type = /*>|>*/ ctx.traceIndented(s"lub(${tp1.show}, ${tp2.show})", subtyping, show = true) /*<|<*/ { if (tp1 eq tp2) tp1 else if (!tp1.exists) tp1 else if (!tp2.exists) tp2 diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index d0a681f90..f1e6f5a52 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -7,7 +7,7 @@ import Contexts.Context, Scopes.Scope, Denotations._, Annotations.Annotation import StdNames.nme import ast.{Trees, untpd} import typer.Namer -import typer.ProtoTypes.{SelectionProto, ViewProto, FunProto, IgnoredProto} +import typer.ProtoTypes.{SelectionProto, ViewProto, FunProto, IgnoredProto, dummyTreeOfType} import Trees._ import scala.annotation.switch @@ -126,7 +126,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case tp: ViewProto => return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType) case FunProto(args, resultType, _) => - return "funproto(" ~ toTextGlobal(args, ", ") ~ "):" ~ toText(resultType) + val argsText = args match { + case dummyTreeOfType(tp) :: Nil if !(tp isRef defn.NullClass) => "null: " ~ toText(tp) + case _ => toTextGlobal(args, ", ") + } + return "FunProto(" ~ argsText ~ "):" ~ toText(resultType) case tp: IgnoredProto => return "?" case _ => diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index a72e98418..8bbd3d5d9 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -413,5 +413,11 @@ object ProtoTypes { private lazy val dummyTree = untpd.Literal(Constant(null)) /** Dummy tree to be used as an argument of a FunProto or ViewProto type */ - def dummyTreeOfType(tp: Type): Tree = dummyTree withTypeUnchecked tp + object dummyTreeOfType { + def apply(tp: Type): Tree = dummyTree withTypeUnchecked tp + def unapply(tree: Tree): Option[Type] = tree match { + case Literal(Constant(null)) => Some(tree.tpe) + case _ => None + } + } } \ No newline at end of file -- cgit v1.2.3 From 3b247c34a4c8959b638c61b116635d6c7e80403a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 11:28:38 +0200 Subject: Reporter fix This fixes a bug introuced by 7754c1ee6c4230e424fd99b820471dbd2c1c8390. The reporter state need to be reset undconditionally in a tryWithFallback. --- src/dotty/tools/dotc/core/TyperState.scala | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala index 6a3ac4467..8c742edab 100644 --- a/src/dotty/tools/dotc/core/TyperState.scala +++ b/src/dotty/tools/dotc/core/TyperState.scala @@ -152,12 +152,13 @@ extends TyperState(r) { val savedConstraint = myConstraint myReporter = new StoreReporter val result = op - if (!reporter.hasErrors) result - else { - myReporter = savedReporter - myConstraint = savedConstraint - fallback - } + try + if (!reporter.hasErrors) result + else { + myConstraint = savedConstraint + fallback + } + finally myReporter = savedReporter } override def toText(printer: Printer): Text = constraint.toText(printer) -- cgit v1.2.3 From 05668169eca68bbdc777fbf698f92e256f8e50a9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 May 2014 14:37:40 +0200 Subject: Fix of t2504 Another problem where we need to insert an implicit on the result type of complex operation. Two additions: (1) If adapt fails, we now try with a weaker FunProto without result type, thus allowing for an additional implicit cpmversion on the result. (2) An Application in a committable context will not fail if the result type does not match the expected one. The problem will be simply deferred in that case. --- src/dotty/tools/dotc/typer/Applications.scala | 13 ++++-- src/dotty/tools/dotc/typer/Typer.scala | 64 ++++++++++++++++++--------- tests/pos/t2504.scala | 6 +++ tests/pos/test.scala | 6 --- tests/untried/pos/t2500.scala | 6 --- tests/untried/pos/t2504.scala | 5 --- tests/untried/pos/t252.scala | 17 ------- tests/untried/pos/t2545.scala | 10 ----- tests/untried/pos/t2569/Child.scala | 9 ---- tests/untried/pos/t2569/Parent.java | 13 ------ tests/untried/pos/t2591.scala | 15 ------- 11 files changed, 59 insertions(+), 105 deletions(-) create mode 100755 tests/pos/t2504.scala delete mode 100644 tests/pos/test.scala delete mode 100644 tests/untried/pos/t2500.scala delete mode 100755 tests/untried/pos/t2504.scala delete mode 100644 tests/untried/pos/t252.scala delete mode 100755 tests/untried/pos/t2545.scala delete mode 100644 tests/untried/pos/t2569/Child.scala delete mode 100644 tests/untried/pos/t2569/Parent.java delete mode 100644 tests/untried/pos/t2591.scala diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index a4c26080d..023063585 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -125,9 +125,16 @@ trait Applications extends Compatibility { self: Typer => protected def init() = methType match { case methType: MethodType => // apply the result type constraint, unless method type is dependent - if (!methType.isDependent) + if (!methType.isDependent) { + val savedConstraint = ctx.typerState.constraint if (!constrainResult(methType.resultType, resultType)) - fail(err.typeMismatchStr(methType.resultType, resultType)) + if (ctx.typerState.isCommittable) + // defer the problem until after the application; + // it might be healed by an implicit conversion + assert(ctx.typerState.constraint eq savedConstraint) + else + fail(err.typeMismatchStr(methType.resultType, resultType)) + } // match all arguments with corresponding formal parameters matchArgs(orderedArgs, methType.paramTypes, 0) case _ => @@ -454,7 +461,7 @@ trait Applications extends Compatibility { self: Typer => val result = app.result ConstFold(result) } { (failedVal, failedState) => - val fun2 = tryInsertImplicit(fun1, proto) + val fun2 = tryInsertImplicits(fun1, proto) if (fun1 eq fun2) { failedState.commit() failedVal diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 050fcbc76..3698c648c 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1009,40 +1009,62 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - /** Try to insert `.apply` so that the result conforms to prototype `pt`. - * If that fails try to insert an implicit conversion around the qualifier - * part of `tree`. If either result conforms to `pt`, adapt it, else - * continue with `fallBack`. + private def noResultProto(pt: Type) = pt match { + case pt: FunProto => pt.derivedFunProto(pt.args, WildcardType, pt.typer) // drop result type, because views are disabled + case _ => pt + } + + /** Add apply node or implicit conversions. Three strategies are tried, and the first + * that is succesful is picked. If none of the strategies are succesful, continues with + * `fallBack`. + * + * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`. + * 2nd strategy: If the expected type is a FunProto with a non-wildcard resulttype, + * try to match against the FunProto with wildcard resulttype (this allows for an additional + * implicit conversion on the result). + * 3rd stratgey: If tree is a select `qual.name`, try to insert an implicit conversion + * around the qualifier part `qual` so that the result conforms to the expected type + * with wildcard result type. */ def tryInsertApplyOrImplicit(tree: Tree, pt: ProtoType)(fallBack: (Tree, TyperState) => Tree)(implicit ctx: Context): Tree = tryEither { implicit ctx => val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt) if (sel.tpe.isError) sel else adapt(sel, pt) } { (failedTree, failedState) => - val tree1 = tryInsertImplicit(tree, pt) + val tree1 = tryInsertImplicits(tree, pt) if (tree1 eq tree) fallBack(failedTree, failedState) - else adapt(tree1, pt) + else adapt(tree1, noResultProto(pt)) } + def tryInsertImplicits(tree: Tree, pt: ProtoType)(implicit ctx: Context): Tree = { + val normalizedProto = noResultProto(pt) + if (normalizedProto eq pt) tryInsertImplicitOnQualifier(tree, pt) + else tryEither { implicit ctx => + val tree1 = adaptInterpolated(tree, normalizedProto, EmptyTree) + if (tree1 eq tree) ctx.error("no progress") + tree1 + } { (_, _) => + tryInsertImplicitOnQualifier(tree, normalizedProto) + } + } + /** If this tree is a select node `qual.name`, try to insert an implicit conversion * `c` around `qual` so that `c(qual).name` conforms to `pt`. If that fails * return `tree` itself. */ - def tryInsertImplicit(tree: Tree, pt: ProtoType)(implicit ctx: Context): Tree = ctx.traceIndented(i"try ins impl $tree $pt") { tree match { - case Select(qual, name) => - val normalizedProto = pt match { - case pt: FunProto => pt.derivedFunProto(pt.args, WildcardType, pt.typer) // drop result type, because views are disabled - case _ => pt - } - val qualProto = SelectionProto(name, normalizedProto, NoViewsAllowed) - tryEither { implicit ctx => - val qual1 = adaptInterpolated(qual, qualProto, EmptyTree) - if ((qual eq qual1) || ctx.reporter.hasErrors) tree - else typedSelect(cpy.Select(tree, untpd.TypedSplice(qual1), name), pt) - } { (_, _) => tree - } - case _ => tree - }} + def tryInsertImplicitOnQualifier(tree: Tree, pt: Type)(implicit ctx: Context): Tree = ctx.traceIndented(i"try insert impl on qualifier $tree $pt") { + tree match { + case Select(qual, name) => + val qualProto = SelectionProto(name, pt, NoViewsAllowed) + tryEither { implicit ctx => + val qual1 = adaptInterpolated(qual, qualProto, EmptyTree) + if ((qual eq qual1) || ctx.reporter.hasErrors) tree + else typedSelect(cpy.Select(tree, untpd.TypedSplice(qual1), name), pt) + } { (_, _) => tree + } + case _ => tree + } + } def adapt(tree: Tree, pt: Type, original: untpd.Tree = untpd.EmptyTree)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ { /*>|>*/ ctx.traceIndented(i"adapting $tree of type ${tree.tpe} to $pt", typr, show = true) /*<|<*/ { diff --git a/tests/pos/t2504.scala b/tests/pos/t2504.scala new file mode 100755 index 000000000..72117174c --- /dev/null +++ b/tests/pos/t2504.scala @@ -0,0 +1,6 @@ +object Test { + val zs = Array("abc") + val ys: Iterable[_] = Array("abc") + val xs = Array("abc") + xs sameElements Array("abc") +} diff --git a/tests/pos/test.scala b/tests/pos/test.scala deleted file mode 100644 index 71fa1b1d9..000000000 --- a/tests/pos/test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object test { - - val m = new java.util.HashMap[String, String] - m.size - -} \ No newline at end of file diff --git a/tests/untried/pos/t2500.scala b/tests/untried/pos/t2500.scala deleted file mode 100644 index d0ff99a93..000000000 --- a/tests/untried/pos/t2500.scala +++ /dev/null @@ -1,6 +0,0 @@ -object Test { - import scala.collection._ - ((Map(1 -> "a", 2 -> "b"): collection.Map[Int, String]) map identity[(Int, String)]) : scala.collection.Map[Int,String] - ((SortedMap(1 -> "a", 2 -> "b"): collection.SortedMap[Int, String]) map identity[(Int, String)]): scala.collection.SortedMap[Int,String] - ((SortedSet(1, 2): collection.SortedSet[Int]) map identity[Int]): scala.collection.SortedSet[Int] -} diff --git a/tests/untried/pos/t2504.scala b/tests/untried/pos/t2504.scala deleted file mode 100755 index 67f822685..000000000 --- a/tests/untried/pos/t2504.scala +++ /dev/null @@ -1,5 +0,0 @@ -object Test { - val ys: Iterable[_] = Array("abc") - val xs = Array("abc") - xs sameElements Array("abc") -} diff --git a/tests/untried/pos/t252.scala b/tests/untried/pos/t252.scala deleted file mode 100644 index d51b5511e..000000000 --- a/tests/untried/pos/t252.scala +++ /dev/null @@ -1,17 +0,0 @@ -abstract class Module {} - -abstract class T { - type moduleType <: Module - val module: moduleType -} - -abstract class Base { - type mType = Module - type tType = T { type moduleType <: mType } -} - -abstract class Derived extends Base { - def f(inputs: List[tType]): Unit = { - for (t <- inputs; m = t.module) { } - } -} diff --git a/tests/untried/pos/t2545.scala b/tests/untried/pos/t2545.scala deleted file mode 100755 index 6ad994223..000000000 --- a/tests/untried/pos/t2545.scala +++ /dev/null @@ -1,10 +0,0 @@ -trait Frog[T] { - def hello: T - def size: Int - } - - trait OnlyWithFrogs { - self: Frog[_] => - - def sizeStr = size.toString - } diff --git a/tests/untried/pos/t2569/Child.scala b/tests/untried/pos/t2569/Child.scala deleted file mode 100644 index 64f4dc172..000000000 --- a/tests/untried/pos/t2569/Child.scala +++ /dev/null @@ -1,9 +0,0 @@ -package varargs - - class Child extends Parent { - - override def concatenate(strings: String*): String = - strings map("\"" + _ + "\"") mkString("(", ", ", ")") - - } - diff --git a/tests/untried/pos/t2569/Parent.java b/tests/untried/pos/t2569/Parent.java deleted file mode 100644 index 89421becb..000000000 --- a/tests/untried/pos/t2569/Parent.java +++ /dev/null @@ -1,13 +0,0 @@ -package varargs; - - public class Parent { - - public String concatenate(String... strings) { - StringBuilder builder = new StringBuilder(); - for (String s : strings) { - builder.append(s); - } - return builder.toString(); - } - - } diff --git a/tests/untried/pos/t2591.scala b/tests/untried/pos/t2591.scala deleted file mode 100644 index 47ae551bf..000000000 --- a/tests/untried/pos/t2591.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A -class B - -object Implicits { - implicit def imp(x: A): Int = 41 - implicit def imp(x: B): Int = 41 -} - -object Test { - // should cause imp to be in scope so that the next expression type checks - // `import Implicits._` works - import Implicits.imp - - (new A) : Int -} -- cgit v1.2.3 From e42388682094c63055440c8915d8215935007584 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 11:55:36 +0200 Subject: Added t25xx tests --- tests/disabled/java-interop/pos/t2569/Child.scala | 9 +++++++++ tests/disabled/java-interop/pos/t2569/Parent.java | 13 +++++++++++++ tests/pending/pos/t2591.scala | 15 +++++++++++++++ tests/pos/t2500.scala | 6 ++++++ tests/pos/t252.scala | 17 +++++++++++++++++ tests/pos/t2545.scala | 10 ++++++++++ 6 files changed, 70 insertions(+) create mode 100644 tests/disabled/java-interop/pos/t2569/Child.scala create mode 100644 tests/disabled/java-interop/pos/t2569/Parent.java create mode 100644 tests/pending/pos/t2591.scala create mode 100644 tests/pos/t2500.scala create mode 100644 tests/pos/t252.scala create mode 100755 tests/pos/t2545.scala diff --git a/tests/disabled/java-interop/pos/t2569/Child.scala b/tests/disabled/java-interop/pos/t2569/Child.scala new file mode 100644 index 000000000..64f4dc172 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2569/Child.scala @@ -0,0 +1,9 @@ +package varargs + + class Child extends Parent { + + override def concatenate(strings: String*): String = + strings map("\"" + _ + "\"") mkString("(", ", ", ")") + + } + diff --git a/tests/disabled/java-interop/pos/t2569/Parent.java b/tests/disabled/java-interop/pos/t2569/Parent.java new file mode 100644 index 000000000..89421becb --- /dev/null +++ b/tests/disabled/java-interop/pos/t2569/Parent.java @@ -0,0 +1,13 @@ +package varargs; + + public class Parent { + + public String concatenate(String... strings) { + StringBuilder builder = new StringBuilder(); + for (String s : strings) { + builder.append(s); + } + return builder.toString(); + } + + } diff --git a/tests/pending/pos/t2591.scala b/tests/pending/pos/t2591.scala new file mode 100644 index 000000000..47ae551bf --- /dev/null +++ b/tests/pending/pos/t2591.scala @@ -0,0 +1,15 @@ +class A +class B + +object Implicits { + implicit def imp(x: A): Int = 41 + implicit def imp(x: B): Int = 41 +} + +object Test { + // should cause imp to be in scope so that the next expression type checks + // `import Implicits._` works + import Implicits.imp + + (new A) : Int +} diff --git a/tests/pos/t2500.scala b/tests/pos/t2500.scala new file mode 100644 index 000000000..d0ff99a93 --- /dev/null +++ b/tests/pos/t2500.scala @@ -0,0 +1,6 @@ +object Test { + import scala.collection._ + ((Map(1 -> "a", 2 -> "b"): collection.Map[Int, String]) map identity[(Int, String)]) : scala.collection.Map[Int,String] + ((SortedMap(1 -> "a", 2 -> "b"): collection.SortedMap[Int, String]) map identity[(Int, String)]): scala.collection.SortedMap[Int,String] + ((SortedSet(1, 2): collection.SortedSet[Int]) map identity[Int]): scala.collection.SortedSet[Int] +} diff --git a/tests/pos/t252.scala b/tests/pos/t252.scala new file mode 100644 index 000000000..d51b5511e --- /dev/null +++ b/tests/pos/t252.scala @@ -0,0 +1,17 @@ +abstract class Module {} + +abstract class T { + type moduleType <: Module + val module: moduleType +} + +abstract class Base { + type mType = Module + type tType = T { type moduleType <: mType } +} + +abstract class Derived extends Base { + def f(inputs: List[tType]): Unit = { + for (t <- inputs; m = t.module) { } + } +} diff --git a/tests/pos/t2545.scala b/tests/pos/t2545.scala new file mode 100755 index 000000000..6ad994223 --- /dev/null +++ b/tests/pos/t2545.scala @@ -0,0 +1,10 @@ +trait Frog[T] { + def hello: T + def size: Int + } + + trait OnlyWithFrogs { + self: Frog[_] => + + def sizeStr = size.toString + } -- cgit v1.2.3 From 4a071ad51e4ccc94c34e0fcbea84d48cd8bb214c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 12:36:43 +0200 Subject: Fix of t2591. Needed to wrap a dummyTreeOfType in a TypedSplice to prevent re-typechecking. (In fact, the "tree without pos" check revealed a deeper problem: DummyTrees of types could be typed again, but without the surrounding TypedSplice, the originally stored type would be forgotten and Null would be returned. --- src/dotty/tools/dotc/typer/Implicits.scala | 2 +- src/dotty/tools/dotc/typer/Typer.scala | 7 ++++++- tests/pending/pos/t2591.scala | 15 --------------- tests/pos/t2591.scala | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 tests/pending/pos/t2591.scala create mode 100644 tests/pos/t2591.scala diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index d2a94e287..86d513fff 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -441,7 +441,7 @@ trait Implicits { self: Typer => lazy val funProto = fullProto match { case proto: ViewProto => - FunProto(dummyTreeOfType(proto.argType) :: Nil, proto.resultType, self) + FunProto(untpd.TypedSplice(dummyTreeOfType(proto.argType)) :: Nil, proto.resultType, self) case proto => proto } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 3698c648c..e3683d2cf 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -46,6 +46,11 @@ object Typer { val nothingBound = 0 def isImportPrec(prec: Int) = prec == namedImport || prec == wildImport } + + /** Assert tree has a position, unless it is empty or a typed splice */ + def assertPositioned(tree: untpd.Tree)(implicit ctx: Context) = + if (!tree.isEmpty && !tree.isInstanceOf[untpd.TypedSplice] && ctx.typerState.isGlobalCommittable) + assert(tree.pos.exists, s"position not set for $tree # ${tree.uniqueId}") } class Typer extends Namer with TypeAssigner with Applications with Implicits with Inferencing with Checking { @@ -953,7 +958,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree", typr, show = true) /*<|<*/ { - if (!tree.isEmpty && ctx.typerState.isGlobalCommittable) assert(tree.pos.exists, i"position not set for $tree") + assertPositioned(tree) try adapt(typedUnadapted(tree, pt), pt, tree) catch { case ex: CyclicReference => errorTree(tree, cyclicErrorMsg(ex)) diff --git a/tests/pending/pos/t2591.scala b/tests/pending/pos/t2591.scala deleted file mode 100644 index 47ae551bf..000000000 --- a/tests/pending/pos/t2591.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A -class B - -object Implicits { - implicit def imp(x: A): Int = 41 - implicit def imp(x: B): Int = 41 -} - -object Test { - // should cause imp to be in scope so that the next expression type checks - // `import Implicits._` works - import Implicits.imp - - (new A) : Int -} diff --git a/tests/pos/t2591.scala b/tests/pos/t2591.scala new file mode 100644 index 000000000..47ae551bf --- /dev/null +++ b/tests/pos/t2591.scala @@ -0,0 +1,15 @@ +class A +class B + +object Implicits { + implicit def imp(x: A): Int = 41 + implicit def imp(x: B): Int = 41 +} + +object Test { + // should cause imp to be in scope so that the next expression type checks + // `import Implicits._` works + import Implicits.imp + + (new A) : Int +} -- cgit v1.2.3 From 20034dd5500815ff04052cbc9a97deddacb3e892 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 13:57:21 +0200 Subject: Fix of t2660. Auxiliary constructors need to be wrapped in the type parameters of the primary constructor. Otherwise they will not take part in type inference. --- src/dotty/tools/dotc/ast/Desugar.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 513dee2ff..ba2b62faa 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -241,6 +241,14 @@ object desugar { val constr = cpy.DefDef(constr1, constr1.mods, constr1.name, constrTparams, constrVparamss, constr1.tpt, constr1.rhs) + // Add constructor type parameters to auxiliary constructors + val normalizedBody = body map { + case ddef: DefDef if ddef.name.isConstructorName => + cpy.DefDef(ddef, ddef.mods, ddef.name, constrTparams, ddef.vparamss, ddef.tpt, ddef.rhs) + case stat => + stat + } + val derivedTparams = constrTparams map derivedTypeParam val derivedVparamss = constrVparamss nestedMap derivedTermParam val arity = constrVparamss.head.length @@ -376,7 +384,7 @@ object desugar { } cpy.TypeDef(cdef, mods, name, cpy.Template(impl, constr, parents1, self1, - tparamAccessors ::: vparamAccessors ::: body ::: caseClassMeths)) + tparamAccessors ::: vparamAccessors ::: normalizedBody ::: caseClassMeths)) } // install the watch on classTycon -- cgit v1.2.3 From 772d57cd0874d992b3d5bad12e8f30746b24f5d6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 13:58:25 +0200 Subject: typedTyped needs to maintain Mode. The first part of a type ascription e: T can be a pattern or an expression. The mode has to be kept depending on what it was on the outside. --- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 3 ++- src/dotty/tools/dotc/typer/Typer.scala | 4 ++-- tests/new/t2660.scala | 25 ++++++++++++++++++++++ tests/pending/pos/tuplePatDef.scala | 4 ++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/new/t2660.scala create mode 100644 tests/pending/pos/tuplePatDef.scala diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index f1e6f5a52..eb6b151b4 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -3,7 +3,7 @@ package printing import core._ import Texts._, Types._, Flags._, Names._, Symbols._, NameOps._, Constants._ -import Contexts.Context, Scopes.Scope, Denotations._, Annotations.Annotation +import Contexts.Context, Scopes.Scope, Denotations._, SymDenotations._, Annotations.Annotation import StdNames.nme import ast.{Trees, untpd} import typer.Namer @@ -481,6 +481,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override def toText(denot: Denotation): Text = denot match { case denot: MultiDenotation => denot.toString + case NoDenotation => "NoDenotation" case _ => if (denot.symbol.exists) toText(denot.symbol) else "some " ~ toText(denot.info) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index e3683d2cf..32680e34b 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -328,7 +328,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val tpt1 = typedType(tree.tpt) val expr1 = if (isWildcard) tree.expr withType tpt1.tpe - else typedExpr(tree.expr, tpt1.tpe) + else typed(tree.expr, tpt1.tpe) assignType(cpy.Typed(tree, expr1, tpt1), tpt1) } tree.expr match { @@ -957,7 +957,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree", typr, show = true) /*<|<*/ { + def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree, patternMode = ${ctx.mode is Mode.Pattern}", typr, show = true) /*<|<*/ { assertPositioned(tree) try adapt(typedUnadapted(tree, pt), pt, tree) catch { diff --git a/tests/new/t2660.scala b/tests/new/t2660.scala new file mode 100644 index 000000000..94a40f740 --- /dev/null +++ b/tests/new/t2660.scala @@ -0,0 +1,25 @@ +package hoho + +class G + +class H extends G + +class A[T](x: T) { + + def this(y: G, z: T) = { + this(z) + print(1) + } + + def this(z: H, h: T) = { + this(h) + print(2) + } +} + +object T { + def main(args: Array[String]): Unit = { + implicit def g2h(g: G): H = new H + new A[Int](new H, 23) + } +} diff --git a/tests/pending/pos/tuplePatDef.scala b/tests/pending/pos/tuplePatDef.scala new file mode 100644 index 000000000..978052991 --- /dev/null +++ b/tests/pending/pos/tuplePatDef.scala @@ -0,0 +1,4 @@ + +object Test { + val (x,y): (String, M) = null +} -- cgit v1.2.3 From 996f47d48c3c10c51da58558643ec02844e45687 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 14:00:49 +0200 Subject: tests t26xx --- tests/new/t2660.scala | 25 -------------- tests/pending/pos/t2613.scala | 11 ++++++ tests/pending/pos/t2693.scala | 6 ++++ tests/pos/t2610.scala | 17 +++++++++ tests/pos/t2619.scala | 80 +++++++++++++++++++++++++++++++++++++++++++ tests/pos/t262.scala | 14 ++++++++ tests/pos/t2624.scala | 4 +++ tests/pos/t2635.scala | 16 +++++++++ tests/pos/t2660.scala | 25 ++++++++++++++ tests/pos/t2664.scala | 9 +++++ tests/pos/t2665.scala | 3 ++ tests/pos/t2667.scala | 6 ++++ tests/pos/t2669.scala | 28 +++++++++++++++ tests/pos/t267.scala | 55 +++++++++++++++++++++++++++++ tests/pos/t2683.scala | 7 ++++ tests/pos/t2691.scala | 16 +++++++++ tests/pos/t2698.scala | 14 ++++++++ 17 files changed, 311 insertions(+), 25 deletions(-) delete mode 100644 tests/new/t2660.scala create mode 100644 tests/pending/pos/t2613.scala create mode 100644 tests/pending/pos/t2693.scala create mode 100644 tests/pos/t2610.scala create mode 100644 tests/pos/t2619.scala create mode 100644 tests/pos/t262.scala create mode 100644 tests/pos/t2624.scala create mode 100755 tests/pos/t2635.scala create mode 100644 tests/pos/t2660.scala create mode 100644 tests/pos/t2664.scala create mode 100644 tests/pos/t2665.scala create mode 100644 tests/pos/t2667.scala create mode 100644 tests/pos/t2669.scala create mode 100644 tests/pos/t267.scala create mode 100755 tests/pos/t2683.scala create mode 100644 tests/pos/t2691.scala create mode 100644 tests/pos/t2698.scala diff --git a/tests/new/t2660.scala b/tests/new/t2660.scala deleted file mode 100644 index 94a40f740..000000000 --- a/tests/new/t2660.scala +++ /dev/null @@ -1,25 +0,0 @@ -package hoho - -class G - -class H extends G - -class A[T](x: T) { - - def this(y: G, z: T) = { - this(z) - print(1) - } - - def this(z: H, h: T) = { - this(h) - print(2) - } -} - -object T { - def main(args: Array[String]): Unit = { - implicit def g2h(g: G): H = new H - new A[Int](new H, 23) - } -} diff --git a/tests/pending/pos/t2613.scala b/tests/pending/pos/t2613.scala new file mode 100644 index 000000000..c234d4c0d --- /dev/null +++ b/tests/pending/pos/t2613.scala @@ -0,0 +1,11 @@ +import language.existentials + +object Test { + class Row + + abstract class MyRelation [R <: Row, +Relation <: MyRelation[R, Relation]] + + type M = MyRelation[_ <: Row, _ <: MyRelation] + + val (x,y): (String, M) = null +} diff --git a/tests/pending/pos/t2693.scala b/tests/pending/pos/t2693.scala new file mode 100644 index 000000000..5d4d0380c --- /dev/null +++ b/tests/pending/pos/t2693.scala @@ -0,0 +1,6 @@ +class A { + trait T[A] + def usetHk[T[_], A](ta: T[A]) = 0 + usetHk(new T[Int]{}: T[Int]) + usetHk(new T[Int]{}) // fails with: found: java.lang.Object with T[Int], required: ?T[ ?A ] +} diff --git a/tests/pos/t2610.scala b/tests/pos/t2610.scala new file mode 100644 index 000000000..8a82b4a72 --- /dev/null +++ b/tests/pos/t2610.scala @@ -0,0 +1,17 @@ +package mada; package defects; package tests + +package object bbb { + def bar = () + aaa.foo // value foo is not a member of package mada.defects.tests.aaa +} + +package object aaa { + def foo = () +} + +/* compiles successfully if placed here.. +package object bbb { + def bar = () + aaa.foo // value foo is not a member of package mada.defects.tests.aaa +} +*/ diff --git a/tests/pos/t2619.scala b/tests/pos/t2619.scala new file mode 100644 index 000000000..283d93bf2 --- /dev/null +++ b/tests/pos/t2619.scala @@ -0,0 +1,80 @@ +abstract class F { + final def apply(x: Int): AnyRef = null +} +abstract class AbstractModule { + def as: List[AnyRef] + def ms: List[AbstractModule] + def fs: List[F] = Nil + def rs(x: Int): List[AnyRef] = fs.map(_(x)) +} +abstract class ModuleType1 extends AbstractModule {} +abstract class ModuleType2 extends AbstractModule {} + +object ModuleAE extends ModuleType1 { + def as = Nil + def ms = Nil +} +object ModuleAF extends ModuleType2 { + def as = Nil + def ms = List(ModuleAE) +} +object ModuleAG extends ModuleType1 { + def as = List("") + def ms = Nil +} +object ModuleAI extends ModuleType1 { + def as = Nil + def ms = List(ModuleAE) +} +object ModuleAK extends ModuleType2 { + def as = Nil + def ms = List(ModuleAF) +} +object ModuleAL extends ModuleType1 { + def as = Nil + def ms = List( + ModuleAG, + ModuleAI + ) +} +object ModuleAM extends ModuleType1 { + def as = Nil + def ms = List( + ModuleAL, + ModuleAE + ) ::: List(ModuleAK) +} +object ModuleBE extends ModuleType1 { + def as = Nil + def ms = Nil +} +object ModuleBF extends ModuleType2 { + def as = Nil + def ms = List(ModuleBE) +} +object ModuleBG extends ModuleType1 { + def as = List("") + def ms = Nil +} +object ModuleBI extends ModuleType1 { + def as = Nil + def ms = List(ModuleBE) +} +object ModuleBK extends ModuleType2 { + def as = Nil + def ms = List(ModuleBF) +} +object ModuleBL extends ModuleType1 { + def as = Nil + def ms = List( + ModuleBG, + ModuleBI + ) +} +object ModuleBM extends ModuleType1 { + def as = Nil + def ms = List( + ModuleBL, + ModuleBE + ) ::: List(ModuleBK) +} diff --git a/tests/pos/t262.scala b/tests/pos/t262.scala new file mode 100644 index 000000000..ec6187b36 --- /dev/null +++ b/tests/pos/t262.scala @@ -0,0 +1,14 @@ +object O { + abstract class A { + def f:A; + } + class B extends A { + def f = if(1 == 2) new C else new D; + } + class C extends A { + def f = this; + } + class D extends A { + def f = this; + } +} diff --git a/tests/pos/t2624.scala b/tests/pos/t2624.scala new file mode 100644 index 000000000..76f0e3036 --- /dev/null +++ b/tests/pos/t2624.scala @@ -0,0 +1,4 @@ +object Test { + List(1).map(identity(_)) + List(1).map(identity) // this didn't typecheck before the fix +} diff --git a/tests/pos/t2635.scala b/tests/pos/t2635.scala new file mode 100755 index 000000000..7cd553135 --- /dev/null +++ b/tests/pos/t2635.scala @@ -0,0 +1,16 @@ +abstract class Base + +object Test +{ + def run(c: Class[_ <: Base]): Unit = { + } + + def main(args: Array[String]): Unit = + { + val sc: Option[Class[_ <: Base]] = Some(classOf[Base]) + sc match { + case Some(c) => run(c) + case None => + } + } +} diff --git a/tests/pos/t2660.scala b/tests/pos/t2660.scala new file mode 100644 index 000000000..94a40f740 --- /dev/null +++ b/tests/pos/t2660.scala @@ -0,0 +1,25 @@ +package hoho + +class G + +class H extends G + +class A[T](x: T) { + + def this(y: G, z: T) = { + this(z) + print(1) + } + + def this(z: H, h: T) = { + this(h) + print(2) + } +} + +object T { + def main(args: Array[String]): Unit = { + implicit def g2h(g: G): H = new H + new A[Int](new H, 23) + } +} diff --git a/tests/pos/t2664.scala b/tests/pos/t2664.scala new file mode 100644 index 000000000..7b667d010 --- /dev/null +++ b/tests/pos/t2664.scala @@ -0,0 +1,9 @@ +package pkg1 { + class C { + private[pkg1] def foo: Int = 1 + } + + trait T extends C { + private[pkg1] abstract override def foo = super.foo + 1 + } +} diff --git a/tests/pos/t2665.scala b/tests/pos/t2665.scala new file mode 100644 index 000000000..e46453534 --- /dev/null +++ b/tests/pos/t2665.scala @@ -0,0 +1,3 @@ +object Test { + val x: Unit = Array("") +} diff --git a/tests/pos/t2667.scala b/tests/pos/t2667.scala new file mode 100644 index 000000000..7f1f36f00 --- /dev/null +++ b/tests/pos/t2667.scala @@ -0,0 +1,6 @@ +object A { + def foo(x: Int, y: Int*): Int = 45 + def foo[T](x: T*): Int = 55 + + val x: Unit = foo(23, 23f) +} diff --git a/tests/pos/t2669.scala b/tests/pos/t2669.scala new file mode 100644 index 000000000..72e931178 --- /dev/null +++ b/tests/pos/t2669.scala @@ -0,0 +1,28 @@ +// #2629, #2639, #2669 +object Test2669 { + + def test[T](l: java.util.ArrayList[_ <: T]) = 1 + test(new java.util.ArrayList[String]()) + +} + +import java.util.ArrayList + +object Test2629 { + def main(args: Array[String]): Unit = { + val l = new ArrayList[String](1) + val m = new ArrayList(l) + + println(l.size) + println(m.size) + } +} + + +import java.util.Vector + +// scalac cannot detect lack of type params, but then throws AssertionError later: +class TVector2639 { + val b = new Vector // this line passed without error detected + val a = new Vector(1) // this line caused throwing AssertionError when scalac +} diff --git a/tests/pos/t267.scala b/tests/pos/t267.scala new file mode 100644 index 000000000..7e5876eae --- /dev/null +++ b/tests/pos/t267.scala @@ -0,0 +1,55 @@ +package expAbstractData + +/** A base class consisting of + * - a root trait (i.e. abstract class) `Exp' with an `eval' function + * - an abstract type `exp' bounded by `Exp' + * - a concrete instance class `Num' of `Exp' for numeric literals + */ +trait Base { + type exp <: Exp + + trait Exp { + def eval: Int + } + class Num(v: Int) extends Exp { self: exp => + val value = v + def eval = value + } +} + +object testBase extends App with Base { + type exp = Exp + val term = new Num(2); + Console.println(term.eval) +} + +/** Data extension: An extension of `Base' with `Plus' expressions + */ +trait BasePlus extends Base { + class Plus(l: exp, r: exp) extends Exp { self: exp => + val left = l + val right = r + def eval = left.eval + right.eval + } +} + +/** Operation extension: An extension of `Base' with 'show' methods. + */ +trait Show extends Base { + type exp <: Exp1 + + trait Exp1 extends Exp { + def show: String + } + class Num1(v: Int) extends Num(v) with Exp1 { self: exp with Num1 => + def show = value.toString() + } +} + +/** Operation extension: An extension of `BasePlus' with 'show' methods. + */ +trait ShowPlus extends BasePlus with Show { + class Plus1(l: exp, r: exp) extends Plus(l, r) with Exp1 { self: exp with Plus1 => + def show = left.show + " + " + right.show + } +} diff --git a/tests/pos/t2683.scala b/tests/pos/t2683.scala new file mode 100755 index 000000000..4ba34b554 --- /dev/null +++ b/tests/pos/t2683.scala @@ -0,0 +1,7 @@ +class A +class B extends A + +object Test { + val c: Class[_ <: A] = Class.forName("B").asSubclass(classOf[A]) + val x: Option[Class[_ <: A]] = Some(3).map { case _ => c } +} diff --git a/tests/pos/t2691.scala b/tests/pos/t2691.scala new file mode 100644 index 000000000..5f0ddd122 --- /dev/null +++ b/tests/pos/t2691.scala @@ -0,0 +1,16 @@ +object Breakdown { + def unapplySeq(x: Int): Some[List[String]] = Some(List("", "there")) +} +object Test { + 42 match { + case Breakdown("") => // needed to trigger bug + case Breakdown("", who) => println ("hello " + who) + } +} +object Test2 { + 42 match { + case Breakdown("") => // needed to trigger bug + case Breakdown("foo") => // needed to trigger bug + case Breakdown("", who) => println ("hello " + who) + } +} diff --git a/tests/pos/t2698.scala b/tests/pos/t2698.scala new file mode 100644 index 000000000..bce02e48b --- /dev/null +++ b/tests/pos/t2698.scala @@ -0,0 +1,14 @@ +class WordExp { + abstract class Label + type _labelT <: Label +} + +import scala.collection._ + +abstract class S2 { + val lang: WordExp + type __labelT = lang._labelT + + var deltaq: Array[__labelT] = _ + def delta1 = immutable.Map(deltaq.zipWithIndex: _*) +} -- cgit v1.2.3 From 315c097d3a72077512fa06d7c26e8ad09a8b3f66 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 16 May 2014 14:25:39 +0200 Subject: Triage of tests t27xx-t29xx. --- tests/disabled/java-interop/pos/t2764/Ann.java | 5 ++ tests/disabled/java-interop/pos/t2764/Enum.java | 5 ++ tests/disabled/java-interop/pos/t2764/Use.scala | 6 +++ tests/disabled/java-interop/pos/t294/Ann.java | 3 ++ tests/disabled/java-interop/pos/t294/Ann2.java | 3 ++ tests/disabled/java-interop/pos/t294/Test_1.scala | 7 +++ tests/disabled/java-interop/pos/t294/Test_2.scala | 1 + tests/disabled/java-interop/pos/t2940/Cycle.java | 3 ++ tests/disabled/java-interop/pos/t2940/Error.scala | 12 +++++ .../pos/t2956/BeanDefinitionVisitor.java | 6 +++ tests/disabled/java-interop/pos/t2956/t2956.scala | 7 +++ tests/pending/pos/t2782.scala | 18 +++++++ tests/pending/pos/t2795-new.scala | 19 ++++++++ tests/pending/pos/t2795-old.scala | 17 +++++++ tests/pending/pos/t2913.scala | 55 ++++++++++++++++++++++ tests/pending/pos/t2945.scala | 12 +++++ tests/pending/pos/t2994a.scala | 27 +++++++++++ tests/pending/pos/t2994b.scala | 7 +++ tests/pending/pos/tuplePatDef.scala | 4 -- tests/pos/t2708.scala | 1 + tests/pos/t2726/SQLBuilder_1.scala | 7 +++ tests/pos/t2726/t2726_2.scala | 3 ++ tests/pos/t2741/2741_1.scala | 9 ++++ tests/pos/t2741/2741_2.scala | 5 ++ tests/pos/t2794.scala | 9 ++++ tests/pos/t2797.scala | 9 ++++ tests/pos/t2799.flags | 1 + tests/pos/t2799.scala | 1 + tests/pos/t2809.scala | 20 ++++++++ tests/pos/t2810.scala | 8 ++++ tests/pos/t284-pos.scala | 5 ++ tests/pos/t287.scala | 12 +++++ tests/pos/t289.scala | 5 ++ tests/pos/t2910.scala | 33 +++++++++++++ tests/pos/t2939.scala | 13 +++++ tests/pos/t295.scala | 2 + tests/pos/t296.scala | 3 ++ tests/pos/t2973.scala | 1 + tests/pos/tuplePatDef.scala | 4 ++ tests/untried/pos/t2708.scala | 1 - tests/untried/pos/t2726/SQLBuilder_1.scala | 7 --- tests/untried/pos/t2726/t2726_2.scala | 3 -- tests/untried/pos/t2741/2741_1.scala | 9 ---- tests/untried/pos/t2741/2741_2.scala | 5 -- tests/untried/pos/t2764/Ann.java | 5 -- tests/untried/pos/t2764/Enum.java | 5 -- tests/untried/pos/t2764/Use.scala | 6 --- tests/untried/pos/t2782.scala | 18 ------- tests/untried/pos/t2794.scala | 9 ---- tests/untried/pos/t2795-new.scala | 19 -------- tests/untried/pos/t2795-old.scala | 17 ------- tests/untried/pos/t2797.scala | 9 ---- tests/untried/pos/t2799.flags | 1 - tests/untried/pos/t2799.scala | 1 - tests/untried/pos/t2809.scala | 20 -------- tests/untried/pos/t2810.scala | 8 ---- tests/untried/pos/t284-pos.scala | 5 -- tests/untried/pos/t287.scala | 12 ----- tests/untried/pos/t289.scala | 5 -- tests/untried/pos/t2910.scala | 33 ------------- tests/untried/pos/t2913.scala | 53 --------------------- tests/untried/pos/t2939.scala | 13 ----- tests/untried/pos/t294/Ann.java | 3 -- tests/untried/pos/t294/Ann2.java | 3 -- tests/untried/pos/t294/Test_1.scala | 7 --- tests/untried/pos/t294/Test_2.scala | 1 - tests/untried/pos/t2940/Cycle.java | 3 -- tests/untried/pos/t2940/Error.scala | 12 ----- tests/untried/pos/t2945.scala | 12 ----- tests/untried/pos/t295.scala | 2 - tests/untried/pos/t2956/BeanDefinitionVisitor.java | 6 --- tests/untried/pos/t2956/t2956.scala | 7 --- tests/untried/pos/t296.scala | 3 -- tests/untried/pos/t2973.scala | 1 - tests/untried/pos/t2994a.scala | 27 ----------- tests/untried/pos/t2994b.scala | 7 --- 76 files changed, 364 insertions(+), 362 deletions(-) create mode 100644 tests/disabled/java-interop/pos/t2764/Ann.java create mode 100644 tests/disabled/java-interop/pos/t2764/Enum.java create mode 100644 tests/disabled/java-interop/pos/t2764/Use.scala create mode 100644 tests/disabled/java-interop/pos/t294/Ann.java create mode 100644 tests/disabled/java-interop/pos/t294/Ann2.java create mode 100644 tests/disabled/java-interop/pos/t294/Test_1.scala create mode 100644 tests/disabled/java-interop/pos/t294/Test_2.scala create mode 100644 tests/disabled/java-interop/pos/t2940/Cycle.java create mode 100644 tests/disabled/java-interop/pos/t2940/Error.scala create mode 100644 tests/disabled/java-interop/pos/t2956/BeanDefinitionVisitor.java create mode 100755 tests/disabled/java-interop/pos/t2956/t2956.scala create mode 100644 tests/pending/pos/t2782.scala create mode 100644 tests/pending/pos/t2795-new.scala create mode 100644 tests/pending/pos/t2795-old.scala create mode 100755 tests/pending/pos/t2913.scala create mode 100644 tests/pending/pos/t2945.scala create mode 100644 tests/pending/pos/t2994a.scala create mode 100644 tests/pending/pos/t2994b.scala delete mode 100644 tests/pending/pos/tuplePatDef.scala create mode 100644 tests/pos/t2708.scala create mode 100644 tests/pos/t2726/SQLBuilder_1.scala create mode 100644 tests/pos/t2726/t2726_2.scala create mode 100644 tests/pos/t2741/2741_1.scala create mode 100644 tests/pos/t2741/2741_2.scala create mode 100644 tests/pos/t2794.scala create mode 100644 tests/pos/t2797.scala create mode 100644 tests/pos/t2799.flags create mode 100644 tests/pos/t2799.scala create mode 100644 tests/pos/t2809.scala create mode 100644 tests/pos/t2810.scala create mode 100644 tests/pos/t284-pos.scala create mode 100644 tests/pos/t287.scala create mode 100644 tests/pos/t289.scala create mode 100644 tests/pos/t2910.scala create mode 100644 tests/pos/t2939.scala create mode 100644 tests/pos/t295.scala create mode 100644 tests/pos/t296.scala create mode 100644 tests/pos/t2973.scala create mode 100644 tests/pos/tuplePatDef.scala delete mode 100644 tests/untried/pos/t2708.scala delete mode 100644 tests/untried/pos/t2726/SQLBuilder_1.scala delete mode 100644 tests/untried/pos/t2726/t2726_2.scala delete mode 100644 tests/untried/pos/t2741/2741_1.scala delete mode 100644 tests/untried/pos/t2741/2741_2.scala delete mode 100644 tests/untried/pos/t2764/Ann.java delete mode 100644 tests/untried/pos/t2764/Enum.java delete mode 100644 tests/untried/pos/t2764/Use.scala delete mode 100644 tests/untried/pos/t2782.scala delete mode 100644 tests/untried/pos/t2794.scala delete mode 100644 tests/untried/pos/t2795-new.scala delete mode 100644 tests/untried/pos/t2795-old.scala delete mode 100644 tests/untried/pos/t2797.scala delete mode 100644 tests/untried/pos/t2799.flags delete mode 100644 tests/untried/pos/t2799.scala delete mode 100644 tests/untried/pos/t2809.scala delete mode 100644 tests/untried/pos/t2810.scala delete mode 100644 tests/untried/pos/t284-pos.scala delete mode 100644 tests/untried/pos/t287.scala delete mode 100644 tests/untried/pos/t289.scala delete mode 100644 tests/untried/pos/t2910.scala delete mode 100755 tests/untried/pos/t2913.scala delete mode 100644 tests/untried/pos/t2939.scala delete mode 100644 tests/untried/pos/t294/Ann.java delete mode 100644 tests/untried/pos/t294/Ann2.java delete mode 100644 tests/untried/pos/t294/Test_1.scala delete mode 100644 tests/untried/pos/t294/Test_2.scala delete mode 100644 tests/untried/pos/t2940/Cycle.java delete mode 100644 tests/untried/pos/t2940/Error.scala delete mode 100644 tests/untried/pos/t2945.scala delete mode 100644 tests/untried/pos/t295.scala delete mode 100644 tests/untried/pos/t2956/BeanDefinitionVisitor.java delete mode 100755 tests/untried/pos/t2956/t2956.scala delete mode 100644 tests/untried/pos/t296.scala delete mode 100644 tests/untried/pos/t2973.scala delete mode 100644 tests/untried/pos/t2994a.scala delete mode 100644 tests/untried/pos/t2994b.scala diff --git a/tests/disabled/java-interop/pos/t2764/Ann.java b/tests/disabled/java-interop/pos/t2764/Ann.java new file mode 100644 index 000000000..184fc6e86 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2764/Ann.java @@ -0,0 +1,5 @@ +package bippy; + +public @interface Ann { + Enum value(); +} diff --git a/tests/disabled/java-interop/pos/t2764/Enum.java b/tests/disabled/java-interop/pos/t2764/Enum.java new file mode 100644 index 000000000..fe0755953 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2764/Enum.java @@ -0,0 +1,5 @@ +package bippy; + +public enum Enum { + VALUE; +} diff --git a/tests/disabled/java-interop/pos/t2764/Use.scala b/tests/disabled/java-interop/pos/t2764/Use.scala new file mode 100644 index 000000000..b0c108907 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2764/Use.scala @@ -0,0 +1,6 @@ +package bippy + +class Use { + @Ann(Enum.VALUE) + def foo: Unit = {} +} diff --git a/tests/disabled/java-interop/pos/t294/Ann.java b/tests/disabled/java-interop/pos/t294/Ann.java new file mode 100644 index 000000000..934ca4629 --- /dev/null +++ b/tests/disabled/java-interop/pos/t294/Ann.java @@ -0,0 +1,3 @@ +public @interface Ann { + public Ann2[] nested(); +} diff --git a/tests/disabled/java-interop/pos/t294/Ann2.java b/tests/disabled/java-interop/pos/t294/Ann2.java new file mode 100644 index 000000000..025b79e79 --- /dev/null +++ b/tests/disabled/java-interop/pos/t294/Ann2.java @@ -0,0 +1,3 @@ +public @interface Ann2 { + public int value(); +} diff --git a/tests/disabled/java-interop/pos/t294/Test_1.scala b/tests/disabled/java-interop/pos/t294/Test_1.scala new file mode 100644 index 000000000..ff1f34b10 --- /dev/null +++ b/tests/disabled/java-interop/pos/t294/Test_1.scala @@ -0,0 +1,7 @@ +// also test pickling of java annotations; Test_2.scala will +// read this class file +@Ann(nested = Array(new Ann2(10))) class Test { + @Ann2(100) var ctx: Object = _ + @Ann(nested = Array()) def foo = 10 + @Ann(nested = Array(new Ann2(10), new Ann2(23))) val bam = -3 +} diff --git a/tests/disabled/java-interop/pos/t294/Test_2.scala b/tests/disabled/java-interop/pos/t294/Test_2.scala new file mode 100644 index 000000000..9fb1c6e17 --- /dev/null +++ b/tests/disabled/java-interop/pos/t294/Test_2.scala @@ -0,0 +1 @@ +class Test2 extends Test diff --git a/tests/disabled/java-interop/pos/t2940/Cycle.java b/tests/disabled/java-interop/pos/t2940/Cycle.java new file mode 100644 index 000000000..eef6c23b5 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2940/Cycle.java @@ -0,0 +1,3 @@ +public interface Cycle> { + void doStuff(); +} \ No newline at end of file diff --git a/tests/disabled/java-interop/pos/t2940/Error.scala b/tests/disabled/java-interop/pos/t2940/Error.scala new file mode 100644 index 000000000..92f08f580 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2940/Error.scala @@ -0,0 +1,12 @@ +abstract class Error { + val c: Cycle[_] +} + +object Test { + trait Quux[T] extends Cycle[Quux[T]] + val x = new Quux[Int] { def doStuff(): Unit = { } } + + def main(args: Array[String]): Unit = { + + } +} diff --git a/tests/disabled/java-interop/pos/t2956/BeanDefinitionVisitor.java b/tests/disabled/java-interop/pos/t2956/BeanDefinitionVisitor.java new file mode 100644 index 000000000..2ff5daa25 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2956/BeanDefinitionVisitor.java @@ -0,0 +1,6 @@ +import java.util.Map; +public class BeanDefinitionVisitor { + @SuppressWarnings("unchecked") + protected void visitMap(Map mapVal) { + } +} diff --git a/tests/disabled/java-interop/pos/t2956/t2956.scala b/tests/disabled/java-interop/pos/t2956/t2956.scala new file mode 100755 index 000000000..33803874b --- /dev/null +++ b/tests/disabled/java-interop/pos/t2956/t2956.scala @@ -0,0 +1,7 @@ +import scala.collection.JavaConversions._ + +class Outer { + protected class Inner extends BeanDefinitionVisitor { + protected def visitMap(mapVal: Map[_, _]): Unit = () + } +} diff --git a/tests/pending/pos/t2782.scala b/tests/pending/pos/t2782.scala new file mode 100644 index 000000000..3b387af80 --- /dev/null +++ b/tests/pending/pos/t2782.scala @@ -0,0 +1,18 @@ +import scala.{collection => sc} + +object Test { + trait Foo[T] + + // Haven't managed to repro without using a CanBuild or CanBuildFrom implicit parameter + implicit def MapFoo[A, B, M[A, B] <: sc.Map[A,B]](implicit aFoo: Foo[A], bFoo: Foo[B], cb: sc.generic.CanBuild[(A, B), M[A, B]]): Test.Foo[M[A,B]] = new Foo[M[A,B]] {} + implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] // no difference if this line is uncommented + implicit def Tuple2Foo[A, B]: Test.Foo[(A, B)] = new Foo[(A, B)] {} // nor this one + + implicitly[Foo[(Int, Int)]] +} + +class A { + def x[N[X] >: M[X], M[_], G](n: N[G], m: M[G]) = null + + x(Some(3), Seq(2)) +} diff --git a/tests/pending/pos/t2795-new.scala b/tests/pending/pos/t2795-new.scala new file mode 100644 index 000000000..e307133e0 --- /dev/null +++ b/tests/pending/pos/t2795-new.scala @@ -0,0 +1,19 @@ +package t1 + +import scala.reflect.{ClassTag, classTag} + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ClassTag[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/tests/pending/pos/t2795-old.scala b/tests/pending/pos/t2795-old.scala new file mode 100644 index 000000000..935cb1f44 --- /dev/null +++ b/tests/pending/pos/t2795-old.scala @@ -0,0 +1,17 @@ +package t1 + +trait Element[T] { +} + +trait Config { + type T <: Element[T] + implicit val m: ClassManifest[T] + // XXX Following works fine: + // type T <: Element[_] +} + +trait Transform { self: Config => + def processBlock(block: Array[T]): Unit = { + var X = new Array[T](1) + } +} diff --git a/tests/pending/pos/t2913.scala b/tests/pending/pos/t2913.scala new file mode 100755 index 000000000..21700e71a --- /dev/null +++ b/tests/pending/pos/t2913.scala @@ -0,0 +1,55 @@ +import language.noAutoTupling // try with on and off + +class A { + def foo(a: Int) = 0 +} + +class RichA { + def foo(a: String) = 0 + def foo(a: String, b: String) = 0 + def foo() = 0 +} + +object Test { + + implicit def AToRichA(a: A): RichA = new RichA + + val a = new A + a.foo() + a.foo(1) + + a.foo("") // Without implicits, a type error regarding invalid argument types is generated at `""`. This is + // the same position as an argument, so the 'second try' typing with an Implicit View is tried, + // and AToRichA(a).foo("") is found. + // + // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should + // not be triggered. + // + // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756 + + a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo("", "")`. + // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`. + // None of these po +} + +// t0851 is essentially the same: +object test1 { + case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){ + def apply(t : T) = (s:T2) => f(t,s) + def apply(p : (T,T2)) = f(p._1,p._2) + } + implicit def g[T](f : (T,String) => String): test1.Foo[T,String] = Foo(f) + def main(args : Array[String]) : Unit = { + val f = (x:Int,s:String) => s + x + println(f(1)) + () + } +} +object Main { + def main(args : Array[String]): Unit = { + val fn = (a : Int, str : String) => "a: " + a + ", str: " + str + implicit def fx[T](f : (T,String) => String): T => String = (x:T) => f(x,null) + println(fn(1)) + () + } +} diff --git a/tests/pending/pos/t2945.scala b/tests/pending/pos/t2945.scala new file mode 100644 index 000000000..0379e9ba1 --- /dev/null +++ b/tests/pending/pos/t2945.scala @@ -0,0 +1,12 @@ +object Foo { + def test(s: String) = { + (s: Seq[Char]) match { + case Seq('f', 'o', 'o', ' ', rest1 @ _*) => + rest1 + case Seq('b', 'a', 'r', ' ', ' ', rest2 @ _*) => + rest2 + case _ => + s + } + } +} diff --git a/tests/pending/pos/t2994a.scala b/tests/pending/pos/t2994a.scala new file mode 100644 index 000000000..f1a4a4a12 --- /dev/null +++ b/tests/pending/pos/t2994a.scala @@ -0,0 +1,27 @@ +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] + } + +} diff --git a/tests/pending/pos/t2994b.scala b/tests/pending/pos/t2994b.scala new file mode 100644 index 000000000..8b5eb9692 --- /dev/null +++ b/tests/pending/pos/t2994b.scala @@ -0,0 +1,7 @@ +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/pending/pos/tuplePatDef.scala b/tests/pending/pos/tuplePatDef.scala deleted file mode 100644 index 978052991..000000000 --- a/tests/pending/pos/tuplePatDef.scala +++ /dev/null @@ -1,4 +0,0 @@ - -object Test { - val (x,y): (String, M) = null -} diff --git a/tests/pos/t2708.scala b/tests/pos/t2708.scala new file mode 100644 index 000000000..19485bf4c --- /dev/null +++ b/tests/pos/t2708.scala @@ -0,0 +1 @@ +class Foo(@volatile var v: Int) diff --git a/tests/pos/t2726/SQLBuilder_1.scala b/tests/pos/t2726/SQLBuilder_1.scala new file mode 100644 index 000000000..8d07a8826 --- /dev/null +++ b/tests/pos/t2726/SQLBuilder_1.scala @@ -0,0 +1,7 @@ +class SQLBuilder extends SQLBuilder.Segment + +object SQLBuilder { + trait Segment +} + + diff --git a/tests/pos/t2726/t2726_2.scala b/tests/pos/t2726/t2726_2.scala new file mode 100644 index 000000000..e738143ae --- /dev/null +++ b/tests/pos/t2726/t2726_2.scala @@ -0,0 +1,3 @@ +object SQuery2Test { + new SQLBuilder +} diff --git a/tests/pos/t2741/2741_1.scala b/tests/pos/t2741/2741_1.scala new file mode 100644 index 000000000..d9d04f7ab --- /dev/null +++ b/tests/pos/t2741/2741_1.scala @@ -0,0 +1,9 @@ +trait Partial { + type Apply[XYZ] = List[XYZ] +} +trait MA[M[_]] +trait MAs { + val a: MA[Partial#Apply] = null // after compilation, the type is pickled as `MA[ [B] List[B] ]` +} + +object Scalaz extends MAs diff --git a/tests/pos/t2741/2741_2.scala b/tests/pos/t2741/2741_2.scala new file mode 100644 index 000000000..a9fd9d7d0 --- /dev/null +++ b/tests/pos/t2741/2741_2.scala @@ -0,0 +1,5 @@ +// object Test compiles jointly, but not separately. +object Test { + import Scalaz._ + Scalaz.a +} diff --git a/tests/pos/t2794.scala b/tests/pos/t2794.scala new file mode 100644 index 000000000..a17edf8cb --- /dev/null +++ b/tests/pos/t2794.scala @@ -0,0 +1,9 @@ +class Key[T] + +class Entry[T](val k: Key[T], val v: T) + +object Entry { + + def makeDefault[T >: Null <: AnyRef] = new Entry[T](new Key[T], null: T) + +} diff --git a/tests/pos/t2797.scala b/tests/pos/t2797.scala new file mode 100644 index 000000000..cf579d8de --- /dev/null +++ b/tests/pos/t2797.scala @@ -0,0 +1,9 @@ +class MyVector[A] { + def map[B](f: A => B): MyVector[B] = sys.error("") +} + +object Test { + def unzip[B, C](_this: MyVector[(B, C)]): (MyVector[B], MyVector[C]) = { + (_this.map{ bc => bc._1 }, _this.map{ bc => bc._2 }) + } +} diff --git a/tests/pos/t2799.flags b/tests/pos/t2799.flags new file mode 100644 index 000000000..d1b831ea8 --- /dev/null +++ b/tests/pos/t2799.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/pos/t2799.scala b/tests/pos/t2799.scala new file mode 100644 index 000000000..7710cce26 --- /dev/null +++ b/tests/pos/t2799.scala @@ -0,0 +1 @@ +@deprecated("hi mom", "") case class Bob () diff --git a/tests/pos/t2809.scala b/tests/pos/t2809.scala new file mode 100644 index 000000000..1f68b0b07 --- /dev/null +++ b/tests/pos/t2809.scala @@ -0,0 +1,20 @@ +package p1 { + abstract class T1 { + protected def bug(p: Int = 1): Int // without 'protected' compiles fine + } +} +package p2 { // all being in the same package compiles fine + import p1._ + abstract class T2 extends T1 { + class A { + bug() + } + } + + abstract class T3 extends T2 { + class A { + bug() + } + } +} + diff --git a/tests/pos/t2810.scala b/tests/pos/t2810.scala new file mode 100644 index 000000000..c85eca164 --- /dev/null +++ b/tests/pos/t2810.scala @@ -0,0 +1,8 @@ + + + + +object Test { + val closeable1: { def close(): Unit } = new scala.io.Source { val iter: Iterator[Char] = "".iterator } + val closeable2: { def close(): Unit } = new java.io.Closeable { def close() = {} } +} diff --git a/tests/pos/t284-pos.scala b/tests/pos/t284-pos.scala new file mode 100644 index 000000000..40277e2db --- /dev/null +++ b/tests/pos/t284-pos.scala @@ -0,0 +1,5 @@ +trait B[T] { + def f1(a: T): Unit { } + def f2(a: T): Unit + def f3(a: T): Unit = { } +} diff --git a/tests/pos/t287.scala b/tests/pos/t287.scala new file mode 100644 index 000000000..8e5e8831c --- /dev/null +++ b/tests/pos/t287.scala @@ -0,0 +1,12 @@ +object testBuf { + class mystream extends java.io.BufferedOutputStream(new java.io.FileOutputStream("/dev/null")) { + def w( x:String ):Unit = { + val foo = new Array[Byte](2); + + // write( byte[] ) is defined in FilterOutputStream, the superclass of BufferedOutputStream + super.write( foo ); // error + + super.write( foo, 0, foo.length ); // this works however + } + } +} diff --git a/tests/pos/t289.scala b/tests/pos/t289.scala new file mode 100644 index 000000000..96c0244df --- /dev/null +++ b/tests/pos/t289.scala @@ -0,0 +1,5 @@ +class A { + object B; +} + +object C extends A; diff --git a/tests/pos/t2910.scala b/tests/pos/t2910.scala new file mode 100644 index 000000000..f9f2c87a9 --- /dev/null +++ b/tests/pos/t2910.scala @@ -0,0 +1,33 @@ +object Test { + def test1: Unit = { + C + object C + } + + def test2: Unit = { + println(s.length) + lazy val s = "abc" + } + + def test3: Unit = { + lazy val lazyBar = bar + object bar { + val foo = 12 + } + lazy val lazyBar2 = bar + } + + def test4: Unit = { + lazy val x = { + x + lazy val x = 12 + 0 + } + } + + def test5: Unit = { + lazy val f: Int = g + Console.println("foo") + lazy val g: Int = f + } +} diff --git a/tests/pos/t2939.scala b/tests/pos/t2939.scala new file mode 100644 index 000000000..57dd52024 --- /dev/null +++ b/tests/pos/t2939.scala @@ -0,0 +1,13 @@ +import collection._ + +object Proxies { + class C1 extends MapProxy[Int,Int] { def self = Map[Int,Int]() } + class C2 extends mutable.MapProxy[Int,Int] { def self = mutable.Map[Int,Int]() } + class C3 extends immutable.MapProxy[Int,Int] { def self = immutable.Map[Int,Int]() } + + class C4 extends SetProxy[Int] { def self = Set[Int]() } + class C5 extends mutable.SetProxy[Int] { def self = mutable.Set[Int]() } + class C6 extends immutable.SetProxy[Int] { def self = immutable.Set[Int]() } + + class C7 extends SeqProxy[Int] { def self = Seq[Int]() } +} diff --git a/tests/pos/t295.scala b/tests/pos/t295.scala new file mode 100644 index 000000000..22c7beff4 --- /dev/null +++ b/tests/pos/t295.scala @@ -0,0 +1,2 @@ +object Test extends java.rmi.server.UnicastRemoteObject { +} diff --git a/tests/pos/t296.scala b/tests/pos/t296.scala new file mode 100644 index 000000000..0c267a307 --- /dev/null +++ b/tests/pos/t296.scala @@ -0,0 +1,3 @@ +object Bug { + def foo (l: => String) : String = 12 match { case _ => l} +} diff --git a/tests/pos/t2973.scala b/tests/pos/t2973.scala new file mode 100644 index 000000000..f5dde856d --- /dev/null +++ b/tests/pos/t2973.scala @@ -0,0 +1 @@ +package foo {}; package bar {}; package baz {} diff --git a/tests/pos/tuplePatDef.scala b/tests/pos/tuplePatDef.scala new file mode 100644 index 000000000..22f8f8e7d --- /dev/null +++ b/tests/pos/tuplePatDef.scala @@ -0,0 +1,4 @@ + +object Test { + val (x,y): (String, Int) = null +} diff --git a/tests/untried/pos/t2708.scala b/tests/untried/pos/t2708.scala deleted file mode 100644 index 19485bf4c..000000000 --- a/tests/untried/pos/t2708.scala +++ /dev/null @@ -1 +0,0 @@ -class Foo(@volatile var v: Int) diff --git a/tests/untried/pos/t2726/SQLBuilder_1.scala b/tests/untried/pos/t2726/SQLBuilder_1.scala deleted file mode 100644 index 8d07a8826..000000000 --- a/tests/untried/pos/t2726/SQLBuilder_1.scala +++ /dev/null @@ -1,7 +0,0 @@ -class SQLBuilder extends SQLBuilder.Segment - -object SQLBuilder { - trait Segment -} - - diff --git a/tests/untried/pos/t2726/t2726_2.scala b/tests/untried/pos/t2726/t2726_2.scala deleted file mode 100644 index e738143ae..000000000 --- a/tests/untried/pos/t2726/t2726_2.scala +++ /dev/null @@ -1,3 +0,0 @@ -object SQuery2Test { - new SQLBuilder -} diff --git a/tests/untried/pos/t2741/2741_1.scala b/tests/untried/pos/t2741/2741_1.scala deleted file mode 100644 index d9d04f7ab..000000000 --- a/tests/untried/pos/t2741/2741_1.scala +++ /dev/null @@ -1,9 +0,0 @@ -trait Partial { - type Apply[XYZ] = List[XYZ] -} -trait MA[M[_]] -trait MAs { - val a: MA[Partial#Apply] = null // after compilation, the type is pickled as `MA[ [B] List[B] ]` -} - -object Scalaz extends MAs diff --git a/tests/untried/pos/t2741/2741_2.scala b/tests/untried/pos/t2741/2741_2.scala deleted file mode 100644 index a9fd9d7d0..000000000 --- a/tests/untried/pos/t2741/2741_2.scala +++ /dev/null @@ -1,5 +0,0 @@ -// object Test compiles jointly, but not separately. -object Test { - import Scalaz._ - Scalaz.a -} diff --git a/tests/untried/pos/t2764/Ann.java b/tests/untried/pos/t2764/Ann.java deleted file mode 100644 index 184fc6e86..000000000 --- a/tests/untried/pos/t2764/Ann.java +++ /dev/null @@ -1,5 +0,0 @@ -package bippy; - -public @interface Ann { - Enum value(); -} diff --git a/tests/untried/pos/t2764/Enum.java b/tests/untried/pos/t2764/Enum.java deleted file mode 100644 index fe0755953..000000000 --- a/tests/untried/pos/t2764/Enum.java +++ /dev/null @@ -1,5 +0,0 @@ -package bippy; - -public enum Enum { - VALUE; -} diff --git a/tests/untried/pos/t2764/Use.scala b/tests/untried/pos/t2764/Use.scala deleted file mode 100644 index b0c108907..000000000 --- a/tests/untried/pos/t2764/Use.scala +++ /dev/null @@ -1,6 +0,0 @@ -package bippy - -class Use { - @Ann(Enum.VALUE) - def foo: Unit = {} -} diff --git a/tests/untried/pos/t2782.scala b/tests/untried/pos/t2782.scala deleted file mode 100644 index 3b387af80..000000000 --- a/tests/untried/pos/t2782.scala +++ /dev/null @@ -1,18 +0,0 @@ -import scala.{collection => sc} - -object Test { - trait Foo[T] - - // Haven't managed to repro without using a CanBuild or CanBuildFrom implicit parameter - implicit def MapFoo[A, B, M[A, B] <: sc.Map[A,B]](implicit aFoo: Foo[A], bFoo: Foo[B], cb: sc.generic.CanBuild[(A, B), M[A, B]]): Test.Foo[M[A,B]] = new Foo[M[A,B]] {} - implicit object Tuple2IntIntFoo extends Foo[(Int, Int)] // no difference if this line is uncommented - implicit def Tuple2Foo[A, B]: Test.Foo[(A, B)] = new Foo[(A, B)] {} // nor this one - - implicitly[Foo[(Int, Int)]] -} - -class A { - def x[N[X] >: M[X], M[_], G](n: N[G], m: M[G]) = null - - x(Some(3), Seq(2)) -} diff --git a/tests/untried/pos/t2794.scala b/tests/untried/pos/t2794.scala deleted file mode 100644 index a17edf8cb..000000000 --- a/tests/untried/pos/t2794.scala +++ /dev/null @@ -1,9 +0,0 @@ -class Key[T] - -class Entry[T](val k: Key[T], val v: T) - -object Entry { - - def makeDefault[T >: Null <: AnyRef] = new Entry[T](new Key[T], null: T) - -} diff --git a/tests/untried/pos/t2795-new.scala b/tests/untried/pos/t2795-new.scala deleted file mode 100644 index e307133e0..000000000 --- a/tests/untried/pos/t2795-new.scala +++ /dev/null @@ -1,19 +0,0 @@ -package t1 - -import scala.reflect.{ClassTag, classTag} - -trait Element[T] { -} - -trait Config { - type T <: Element[T] - implicit val m: ClassTag[T] - // XXX Following works fine: - // type T <: Element[_] -} - -trait Transform { self: Config => - def processBlock(block: Array[T]): Unit = { - var X = new Array[T](1) - } -} diff --git a/tests/untried/pos/t2795-old.scala b/tests/untried/pos/t2795-old.scala deleted file mode 100644 index 935cb1f44..000000000 --- a/tests/untried/pos/t2795-old.scala +++ /dev/null @@ -1,17 +0,0 @@ -package t1 - -trait Element[T] { -} - -trait Config { - type T <: Element[T] - implicit val m: ClassManifest[T] - // XXX Following works fine: - // type T <: Element[_] -} - -trait Transform { self: Config => - def processBlock(block: Array[T]): Unit = { - var X = new Array[T](1) - } -} diff --git a/tests/untried/pos/t2797.scala b/tests/untried/pos/t2797.scala deleted file mode 100644 index cf579d8de..000000000 --- a/tests/untried/pos/t2797.scala +++ /dev/null @@ -1,9 +0,0 @@ -class MyVector[A] { - def map[B](f: A => B): MyVector[B] = sys.error("") -} - -object Test { - def unzip[B, C](_this: MyVector[(B, C)]): (MyVector[B], MyVector[C]) = { - (_this.map{ bc => bc._1 }, _this.map{ bc => bc._2 }) - } -} diff --git a/tests/untried/pos/t2799.flags b/tests/untried/pos/t2799.flags deleted file mode 100644 index d1b831ea8..000000000 --- a/tests/untried/pos/t2799.flags +++ /dev/null @@ -1 +0,0 @@ --deprecation -Xfatal-warnings \ No newline at end of file diff --git a/tests/untried/pos/t2799.scala b/tests/untried/pos/t2799.scala deleted file mode 100644 index 7710cce26..000000000 --- a/tests/untried/pos/t2799.scala +++ /dev/null @@ -1 +0,0 @@ -@deprecated("hi mom", "") case class Bob () diff --git a/tests/untried/pos/t2809.scala b/tests/untried/pos/t2809.scala deleted file mode 100644 index 1f68b0b07..000000000 --- a/tests/untried/pos/t2809.scala +++ /dev/null @@ -1,20 +0,0 @@ -package p1 { - abstract class T1 { - protected def bug(p: Int = 1): Int // without 'protected' compiles fine - } -} -package p2 { // all being in the same package compiles fine - import p1._ - abstract class T2 extends T1 { - class A { - bug() - } - } - - abstract class T3 extends T2 { - class A { - bug() - } - } -} - diff --git a/tests/untried/pos/t2810.scala b/tests/untried/pos/t2810.scala deleted file mode 100644 index c85eca164..000000000 --- a/tests/untried/pos/t2810.scala +++ /dev/null @@ -1,8 +0,0 @@ - - - - -object Test { - val closeable1: { def close(): Unit } = new scala.io.Source { val iter: Iterator[Char] = "".iterator } - val closeable2: { def close(): Unit } = new java.io.Closeable { def close() = {} } -} diff --git a/tests/untried/pos/t284-pos.scala b/tests/untried/pos/t284-pos.scala deleted file mode 100644 index 40277e2db..000000000 --- a/tests/untried/pos/t284-pos.scala +++ /dev/null @@ -1,5 +0,0 @@ -trait B[T] { - def f1(a: T): Unit { } - def f2(a: T): Unit - def f3(a: T): Unit = { } -} diff --git a/tests/untried/pos/t287.scala b/tests/untried/pos/t287.scala deleted file mode 100644 index 8e5e8831c..000000000 --- a/tests/untried/pos/t287.scala +++ /dev/null @@ -1,12 +0,0 @@ -object testBuf { - class mystream extends java.io.BufferedOutputStream(new java.io.FileOutputStream("/dev/null")) { - def w( x:String ):Unit = { - val foo = new Array[Byte](2); - - // write( byte[] ) is defined in FilterOutputStream, the superclass of BufferedOutputStream - super.write( foo ); // error - - super.write( foo, 0, foo.length ); // this works however - } - } -} diff --git a/tests/untried/pos/t289.scala b/tests/untried/pos/t289.scala deleted file mode 100644 index 96c0244df..000000000 --- a/tests/untried/pos/t289.scala +++ /dev/null @@ -1,5 +0,0 @@ -class A { - object B; -} - -object C extends A; diff --git a/tests/untried/pos/t2910.scala b/tests/untried/pos/t2910.scala deleted file mode 100644 index f9f2c87a9..000000000 --- a/tests/untried/pos/t2910.scala +++ /dev/null @@ -1,33 +0,0 @@ -object Test { - def test1: Unit = { - C - object C - } - - def test2: Unit = { - println(s.length) - lazy val s = "abc" - } - - def test3: Unit = { - lazy val lazyBar = bar - object bar { - val foo = 12 - } - lazy val lazyBar2 = bar - } - - def test4: Unit = { - lazy val x = { - x - lazy val x = 12 - 0 - } - } - - def test5: Unit = { - lazy val f: Int = g - Console.println("foo") - lazy val g: Int = f - } -} diff --git a/tests/untried/pos/t2913.scala b/tests/untried/pos/t2913.scala deleted file mode 100755 index 55b72bed4..000000000 --- a/tests/untried/pos/t2913.scala +++ /dev/null @@ -1,53 +0,0 @@ -class A { - def foo(a: Int) = 0 -} - -class RichA { - def foo(a: String) = 0 - def foo(a: String, b: String) = 0 - def foo() = 0 -} - -object Test { - - implicit def AToRichA(a: A): RichA = new RichA - - val a = new A - a.foo() - a.foo(1) - - a.foo("") // Without implicits, a type error regarding invalid argument types is generated at `""`. This is - // the same position as an argument, so the 'second try' typing with an Implicit View is tried, - // and AToRichA(a).foo("") is found. - // - // My reading of the spec "7.3 Views" is that `a.foo` denotes a member of `a`, so the view should - // not be triggered. - // - // But perhaps the implementation was changed to solve See https://lampsvn.epfl.ch/trac/scala/ticket/1756 - - a.foo("a", "b") // Without implicits, a type error regarding invalid arity is generated at `foo("", "")`. - // Typers#tryTypedApply:3274 only checks if the error is as the same position as `foo`, `"a"`, or `"b"`. - // None of these po -} - -// t0851 is essentially the same: -object test1 { - case class Foo[T,T2](f : (T,T2) => String) extends (((T,T2)) => String){ - def apply(t : T) = (s:T2) => f(t,s) - def apply(p : (T,T2)) = f(p._1,p._2) - } - implicit def g[T](f : (T,String) => String): test1.Foo[T,String] = Foo(f) - def main(args : Array[String]) : Unit = { - val f = (x:Int,s:String) => s + x - println(f(1)) - () - } -} -object Main { - def main(args : Array[String]): Unit = { - val fn = (a : Int, str : String) => "a: " + a + ", str: " + str - implicit def fx[T](f : (T,String) => String): T => String = (x:T) => f(x,null) - println(fn(1)) - () - } -} diff --git a/tests/untried/pos/t2939.scala b/tests/untried/pos/t2939.scala deleted file mode 100644 index 57dd52024..000000000 --- a/tests/untried/pos/t2939.scala +++ /dev/null @@ -1,13 +0,0 @@ -import collection._ - -object Proxies { - class C1 extends MapProxy[Int,Int] { def self = Map[Int,Int]() } - class C2 extends mutable.MapProxy[Int,Int] { def self = mutable.Map[Int,Int]() } - class C3 extends immutable.MapProxy[Int,Int] { def self = immutable.Map[Int,Int]() } - - class C4 extends SetProxy[Int] { def self = Set[Int]() } - class C5 extends mutable.SetProxy[Int] { def self = mutable.Set[Int]() } - class C6 extends immutable.SetProxy[Int] { def self = immutable.Set[Int]() } - - class C7 extends SeqProxy[Int] { def self = Seq[Int]() } -} diff --git a/tests/untried/pos/t294/Ann.java b/tests/untried/pos/t294/Ann.java deleted file mode 100644 index 934ca4629..000000000 --- a/tests/untried/pos/t294/Ann.java +++ /dev/null @@ -1,3 +0,0 @@ -public @interface Ann { - public Ann2[] nested(); -} diff --git a/tests/untried/pos/t294/Ann2.java b/tests/untried/pos/t294/Ann2.java deleted file mode 100644 index 025b79e79..000000000 --- a/tests/untried/pos/t294/Ann2.java +++ /dev/null @@ -1,3 +0,0 @@ -public @interface Ann2 { - public int value(); -} diff --git a/tests/untried/pos/t294/Test_1.scala b/tests/untried/pos/t294/Test_1.scala deleted file mode 100644 index ff1f34b10..000000000 --- a/tests/untried/pos/t294/Test_1.scala +++ /dev/null @@ -1,7 +0,0 @@ -// also test pickling of java annotations; Test_2.scala will -// read this class file -@Ann(nested = Array(new Ann2(10))) class Test { - @Ann2(100) var ctx: Object = _ - @Ann(nested = Array()) def foo = 10 - @Ann(nested = Array(new Ann2(10), new Ann2(23))) val bam = -3 -} diff --git a/tests/untried/pos/t294/Test_2.scala b/tests/untried/pos/t294/Test_2.scala deleted file mode 100644 index 9fb1c6e17..000000000 --- a/tests/untried/pos/t294/Test_2.scala +++ /dev/null @@ -1 +0,0 @@ -class Test2 extends Test diff --git a/tests/untried/pos/t2940/Cycle.java b/tests/untried/pos/t2940/Cycle.java deleted file mode 100644 index eef6c23b5..000000000 --- a/tests/untried/pos/t2940/Cycle.java +++ /dev/null @@ -1,3 +0,0 @@ -public interface Cycle> { - void doStuff(); -} \ No newline at end of file diff --git a/tests/untried/pos/t2940/Error.scala b/tests/untried/pos/t2940/Error.scala deleted file mode 100644 index 92f08f580..000000000 --- a/tests/untried/pos/t2940/Error.scala +++ /dev/null @@ -1,12 +0,0 @@ -abstract class Error { - val c: Cycle[_] -} - -object Test { - trait Quux[T] extends Cycle[Quux[T]] - val x = new Quux[Int] { def doStuff(): Unit = { } } - - def main(args: Array[String]): Unit = { - - } -} diff --git a/tests/untried/pos/t2945.scala b/tests/untried/pos/t2945.scala deleted file mode 100644 index 0379e9ba1..000000000 --- a/tests/untried/pos/t2945.scala +++ /dev/null @@ -1,12 +0,0 @@ -object Foo { - def test(s: String) = { - (s: Seq[Char]) match { - case Seq('f', 'o', 'o', ' ', rest1 @ _*) => - rest1 - case Seq('b', 'a', 'r', ' ', ' ', rest2 @ _*) => - rest2 - case _ => - s - } - } -} diff --git a/tests/untried/pos/t295.scala b/tests/untried/pos/t295.scala deleted file mode 100644 index 22c7beff4..000000000 --- a/tests/untried/pos/t295.scala +++ /dev/null @@ -1,2 +0,0 @@ -object Test extends java.rmi.server.UnicastRemoteObject { -} diff --git a/tests/untried/pos/t2956/BeanDefinitionVisitor.java b/tests/untried/pos/t2956/BeanDefinitionVisitor.java deleted file mode 100644 index 2ff5daa25..000000000 --- a/tests/untried/pos/t2956/BeanDefinitionVisitor.java +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.Map; -public class BeanDefinitionVisitor { - @SuppressWarnings("unchecked") - protected void visitMap(Map mapVal) { - } -} diff --git a/tests/untried/pos/t2956/t2956.scala b/tests/untried/pos/t2956/t2956.scala deleted file mode 100755 index 33803874b..000000000 --- a/tests/untried/pos/t2956/t2956.scala +++ /dev/null @@ -1,7 +0,0 @@ -import scala.collection.JavaConversions._ - -class Outer { - protected class Inner extends BeanDefinitionVisitor { - protected def visitMap(mapVal: Map[_, _]): Unit = () - } -} diff --git a/tests/untried/pos/t296.scala b/tests/untried/pos/t296.scala deleted file mode 100644 index 0c267a307..000000000 --- a/tests/untried/pos/t296.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Bug { - def foo (l: => String) : String = 12 match { case _ => l} -} diff --git a/tests/untried/pos/t2973.scala b/tests/untried/pos/t2973.scala deleted file mode 100644 index f5dde856d..000000000 --- a/tests/untried/pos/t2973.scala +++ /dev/null @@ -1 +0,0 @@ -package foo {}; package bar {}; package baz {} diff --git a/tests/untried/pos/t2994a.scala b/tests/untried/pos/t2994a.scala deleted file mode 100644 index f1a4a4a12..000000000 --- a/tests/untried/pos/t2994a.scala +++ /dev/null @@ -1,27 +0,0 @@ -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] - } - -} diff --git a/tests/untried/pos/t2994b.scala b/tests/untried/pos/t2994b.scala deleted file mode 100644 index 8b5eb9692..000000000 --- a/tests/untried/pos/t2994b.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Test { - trait Bar[X[_]] - trait Baz[S[_] <: Bar[S]] { - type Apply[T] - } - trait Foo[V[_] <: Bar[V]] extends Bar[Baz[V]#Apply] -} -- cgit v1.2.3 From e43c3aaa61e570de1cb80b1766fb3e3988c444a0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 May 2014 14:42:59 +0200 Subject: Reclassifying tests --- test/dotc/tests.scala | 1 + tests/neg/t2994.scala | 35 +++++++++++++++++++++++++++++++++++ tests/pending/pos/t2945.scala | 4 ++-- tests/pending/pos/t2994a.scala | 27 --------------------------- tests/pending/pos/t2994b.scala | 7 ------- 5 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 tests/neg/t2994.scala delete mode 100644 tests/pending/pos/t2994a.scala delete mode 100644 tests/pending/pos/t2994b.scala diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index b102c5e80..c7b0dc044 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -84,6 +84,7 @@ class tests extends CompilerTest { @Test def neg_tailcall2 = compileFile(negDir, "tailcall/tailrec-2", xerrors = 2) @Test def neg_tailcall3 = compileFile(negDir, "tailcall/tailrec-3", xerrors = 2) @Test def neg_t1843 = compileFile(negDir, "t1843", xerrors = 1) + @Test def neg_t2994 = compileFile(negDir, "t2994", xerrors = 13) @Test def dotc = compileDir(dotcDir + "tools/dotc", twice) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) diff --git a/tests/neg/t2994.scala b/tests/neg/t2994.scala new file mode 100644 index 000000000..f3009b12f --- /dev/null +++ b/tests/neg/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/pending/pos/t2945.scala b/tests/pending/pos/t2945.scala index 0379e9ba1..54f0a7724 100644 --- a/tests/pending/pos/t2945.scala +++ b/tests/pending/pos/t2945.scala @@ -1,9 +1,9 @@ object Foo { def test(s: String) = { (s: Seq[Char]) match { - case Seq('f', 'o', 'o', ' ', rest1 @ _*) => + case Seq('f', 'o', 'o', ' ', rest1: _*) => rest1 - case Seq('b', 'a', 'r', ' ', ' ', rest2 @ _*) => + case Seq('b', 'a', 'r', ' ', ' ', rest2: _*) => rest2 case _ => s diff --git a/tests/pending/pos/t2994a.scala b/tests/pending/pos/t2994a.scala deleted file mode 100644 index f1a4a4a12..000000000 --- a/tests/pending/pos/t2994a.scala +++ /dev/null @@ -1,27 +0,0 @@ -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] - } - -} diff --git a/tests/pending/pos/t2994b.scala b/tests/pending/pos/t2994b.scala deleted file mode 100644 index 8b5eb9692..000000000 --- a/tests/pending/pos/t2994b.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Test { - trait Bar[X[_]] - trait Baz[S[_] <: Bar[S]] { - type Apply[T] - } - trait Foo[V[_] <: Bar[V]] extends Bar[Baz[V]#Apply] -} -- cgit v1.2.3 From c70366db8469e81e315fe89672e8321607a7310a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 18 May 2014 13:17:07 +0200 Subject: Always ignore type in selectionProto The type of a SelectionProto needs to be ignorable because there might be an implicit conversion on the selection. E.g. implicit def a2b(x: A): B = ??? val x: { a: A } = ??? val b: B = x.a This was previously handled by allowing implicit conversions in compatibility checks. But it turns out we can afford to ignore the type of a selectProto and unignore on ambiguities later. --- src/dotty/tools/dotc/typer/ProtoTypes.scala | 8 ++++---- src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/pos/implicitonSelect.scala | 8 ++++++++ 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 tests/pos/implicitonSelect.scala diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 8bbd3d5d9..76fe1af31 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -79,8 +79,8 @@ object ProtoTypes { } /** A class marking ignored prototypes that can be reviealed by `deepenProto` */ - case class IgnoredProto(proto: ProtoType) extends UncachedGroundType with MatchAlways { - override def deepenProto(implicit ctx: Context): Type = proto + case class IgnoredProto(ignored: Type) extends UncachedGroundType with MatchAlways { + override def deepenProto(implicit ctx: Context): Type = ignored } def ignoreIfProto(tp: Type): Type = tp match { @@ -145,7 +145,7 @@ object ProtoTypes { if (name.isConstructorName) WildcardType else tp match { case tp: UnapplyFunProto => new UnapplySelectionProto(name) - case tp => SelectionProto(name, ignoreIfProto(tp), typer) + case tp => SelectionProto(name, IgnoredProto(tp), typer) } /** A prototype for expressions [] that are in some unspecified selection operation @@ -416,7 +416,7 @@ object ProtoTypes { object dummyTreeOfType { def apply(tp: Type): Tree = dummyTree withTypeUnchecked tp def unapply(tree: Tree): Option[Type] = tree match { - case Literal(Constant(null)) => Some(tree.tpe) + case Literal(Constant(null)) => Some(tree.typeOpt) case _ => None } } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 32680e34b..0293d1803 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -957,7 +957,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree, patternMode = ${ctx.mode is Mode.Pattern}", typr, show = true) /*<|<*/ { + def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): Tree = /*>|>*/ ctx.traceIndented (i"typing $tree", typr, show = true) /*<|<*/ { assertPositioned(tree) try adapt(typedUnadapted(tree, pt), pt, tree) catch { diff --git a/tests/pos/implicitonSelect.scala b/tests/pos/implicitonSelect.scala new file mode 100644 index 000000000..4f5f90ada --- /dev/null +++ b/tests/pos/implicitonSelect.scala @@ -0,0 +1,8 @@ +object test { + class A + class B + implicit def a2b(x: A): B = new B + class ARef { val a: A = new A } + val x = new ARef + val b: B = x.a +} -- cgit v1.2.3 From 70e785f5d8a583dae127dadf4d9add70bdea71f7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 18 May 2014 16:36:20 +0200 Subject: Simplify result handling in FunProto. Following the example of SelectionProto, we now always hide the result in a FunProto behind an IgnoreProto. This avoids a special case retry with a weaker FunProto in tryInsertApplyOrImplicit. --- src/dotty/tools/dotc/typer/Applications.scala | 4 ++-- src/dotty/tools/dotc/typer/ProtoTypes.scala | 5 ----- src/dotty/tools/dotc/typer/Typer.scala | 30 +++++---------------------- tests/pos/resultGuidesInference.scala | 7 +++++++ 4 files changed, 14 insertions(+), 32 deletions(-) create mode 100644 tests/pos/resultGuidesInference.scala diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 023063585..aaceac0e0 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -441,7 +441,7 @@ trait Applications extends Compatibility { self: Typer => def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = { def realApply(implicit ctx: Context): Tree = track("realApply") { - var proto = new FunProto(tree.args, ignoreIfProto(pt), this) + var proto = new FunProto(tree.args, IgnoredProto(pt), this) val fun1 = typedExpr(tree.fun, proto) // Warning: The following line is dirty and fragile. We record that auto-tupling was demanded as @@ -461,7 +461,7 @@ trait Applications extends Compatibility { self: Typer => val result = app.result ConstFold(result) } { (failedVal, failedState) => - val fun2 = tryInsertImplicits(fun1, proto) + val fun2 = tryInsertImplicitOnQualifier(fun1, proto) if (fun1 eq fun2) { failedState.commit() failedVal diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 76fe1af31..19d8d6895 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -83,11 +83,6 @@ object ProtoTypes { override def deepenProto(implicit ctx: Context): Type = ignored } - def ignoreIfProto(tp: Type): Type = tp match { - case proto: ProtoType => IgnoredProto(proto) - case _ => tp - } - /** A prototype for expressions [] that are part of a selection operation: * * [ ].name: proto diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 0293d1803..d6b724270 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1014,20 +1014,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - private def noResultProto(pt: Type) = pt match { - case pt: FunProto => pt.derivedFunProto(pt.args, WildcardType, pt.typer) // drop result type, because views are disabled - case _ => pt - } - - /** Add apply node or implicit conversions. Three strategies are tried, and the first - * that is succesful is picked. If none of the strategies are succesful, continues with + /** Add apply node or implicit conversions. Two strategies are tried, and the first + * that is succesful is picked. If neither of the strategies are succesful, continues with * `fallBack`. * * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`. - * 2nd strategy: If the expected type is a FunProto with a non-wildcard resulttype, - * try to match against the FunProto with wildcard resulttype (this allows for an additional - * implicit conversion on the result). - * 3rd stratgey: If tree is a select `qual.name`, try to insert an implicit conversion + * 2nd stratgey: If tree is a select `qual.name`, try to insert an implicit conversion * around the qualifier part `qual` so that the result conforms to the expected type * with wildcard result type. */ @@ -1036,23 +1028,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt) if (sel.tpe.isError) sel else adapt(sel, pt) } { (failedTree, failedState) => - val tree1 = tryInsertImplicits(tree, pt) + val tree1 = tryInsertImplicitOnQualifier(tree, pt) if (tree1 eq tree) fallBack(failedTree, failedState) - else adapt(tree1, noResultProto(pt)) + else adapt(tree1, pt) } - def tryInsertImplicits(tree: Tree, pt: ProtoType)(implicit ctx: Context): Tree = { - val normalizedProto = noResultProto(pt) - if (normalizedProto eq pt) tryInsertImplicitOnQualifier(tree, pt) - else tryEither { implicit ctx => - val tree1 = adaptInterpolated(tree, normalizedProto, EmptyTree) - if (tree1 eq tree) ctx.error("no progress") - tree1 - } { (_, _) => - tryInsertImplicitOnQualifier(tree, normalizedProto) - } - } - /** If this tree is a select node `qual.name`, try to insert an implicit conversion * `c` around `qual` so that `c(qual).name` conforms to `pt`. If that fails * return `tree` itself. diff --git a/tests/pos/resultGuidesInference.scala b/tests/pos/resultGuidesInference.scala new file mode 100644 index 000000000..4e02504e0 --- /dev/null +++ b/tests/pos/resultGuidesInference.scala @@ -0,0 +1,7 @@ +object test { + + def foo[T](x: T => T): Array[T] = ??? + + val x: Array[Int] = foo(x => x) + +} -- cgit v1.2.3 From c2175ec910165308e81c48bd8ca8910c50862be4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 28 May 2014 11:27:11 +0200 Subject: Avoid classtype checking for refinements. In a refinement type T { R } we do not need T to be a class. But analyzing the refeinement type will create a temporary class type. This refinement class has to be treated specially in what concerns parent types. --- src/dotty/tools/dotc/core/SymDenotations.scala | 51 ++++++++++++++++++++++++++ src/dotty/tools/dotc/typer/Namer.scala | 3 +- tests/pos/tycons.scala | 22 +++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/pos/tycons.scala diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 498f912f9..606966be9 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -321,6 +321,9 @@ object SymDenotations { final def isAnonymousClass(implicit ctx: Context): Boolean = initial.asSymDenotation.name startsWith tpnme.ANON_CLASS + final def isRefinementClass(implicit ctx: Context): Boolean = + name.decode == tpnme.REFINE_CLASS + /** Is this symbol a package object or its module class? */ def isPackageObject(implicit ctx: Context): Boolean = { val poName = if (isType) nme.PACKAGE_CLS else nme.PACKAGE @@ -701,6 +704,54 @@ object SymDenotations { else Iterator.empty + /** The symbol overriding this symbol in given subclass `ofclazz`. + * + * @param ofclazz is a subclass of this symbol's owner + */ + final def overridingSymbol(inClass: ClassSymbol)(implicit ctx: Context): Symbol = + if (canMatchInheritedSymbols) matchingSymbol(inClass, inClass.thisType) + else NoSymbol + + /** If false, this symbol cannot possibly participate in an override, + * either as overrider or overridee. For internal use; you should consult + * with isOverridingSymbol. This is used by isOverridingSymbol to escape + * the recursive knot. + */ + private def canMatchInheritedSymbols = ( + owner.isClass + && !this.isClass + && !this.isConstructor + ) + + /** The symbol accessed by a super in the definition of this symbol when + * seen from class `base`. This symbol is always concrete. + * pre: `this.owner` is in the base class sequence of `base`. + */ + final def superSymbolIn(base: Symbol)(implicit ctx: Context): Symbol = { + def loop(bcs: List[ClassSymbol]): Symbol = bcs match { + case bc :: bcs1 => + val sym = matchingSymbol(bcs.head, base.thisType) + .suchThat(alt => !(alt is Deferred)).symbol + if (sym.exists) sym else loop(bcs.tail) + case _ => + NoSymbol + } + loop(base.info.baseClasses.dropWhile(owner != _).tail) + } + + + /** A a member of class `base` is incomplete if + * (1) it is declared deferred or + * (2) it is abstract override and its super symbol in `base` is + * nonexistent or incomplete. + */ + final def isIncompleteIn(base: Symbol)(implicit ctx: Context): Boolean = + (this is Deferred) || + (this is AbsOverride) && { + val supersym = superSymbolIn(base) + supersym == NoSymbol || supersym.isIncompleteIn(base) + } + /** The class or term symbol up to which this symbol is accessible, * or RootClass if it is public. As java protected statics are * otherwise completely inaccessible in scala, they are treated diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index e9195a072..681523bd2 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -459,7 +459,8 @@ class Namer { typer: Typer => def checkedParentType(parent: untpd.Tree): Type = { val ptype = parentType(parent)(ctx.fresh addMode Mode.InSuperCall) - checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) + if (cls.isRefinementClass) ptype + else checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) } val selfInfo = diff --git a/tests/pos/tycons.scala b/tests/pos/tycons.scala new file mode 100644 index 000000000..f138c78be --- /dev/null +++ b/tests/pos/tycons.scala @@ -0,0 +1,22 @@ +class TypeConstructor { + type TypeArg +} + +trait List[+T] extends TypeConstructor { type TypeArg <: T } + +trait Set[T] extends TypeConstructor { type TypeArg <: T } + +object obj extends List[Number] with Set[Exception] { + val x: TypeArg = ??? + val n: Number = x + val e: Exception = x +} + +class Functor[F <: TypeConstructor] { + def map[A, B](f: F { type TypeArg <: A }): F { type TypeArg <: B } +} + +implicit object ListFunctor extends Functor[List] { + def map[A, B](f: List[A]): List[B] = ??? +} + -- cgit v1.2.3