From 1b32071acef5c7c2c08e21ee577c7cc709876ffa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 3 May 2014 13:31:27 +0200 Subject: More tests --- tests/pos/t1164.scala | 29 +++++++++++++++++++++++++++++ tests/pos/t1318.scala | 31 +++++++++++++++++++++++++++++++ tests/pos/t1385.scala | 3 +++ tests/pos/t1391.scala | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/pos/t1422_pos.scala | 2 ++ tests/pos/t1438.scala | 10 ++++++++++ tests/pos/t1439.scala | 8 ++++++++ tests/pos/t1480.scala | 6 ++++++ tests/pos/t151.scala | 6 ++++++ tests/pos/t1560.scala | 13 +++++++++++++ tests/pos/t1565.scala | 19 +++++++++++++++++++ tests/pos/t1569.scala | 5 +++++ tests/pos/t159.scala | 22 ++++++++++++++++++++++ tests/pos/t1591_pos.scala | 7 +++++++ tests/pos/t1591b.scala | 13 +++++++++++++ 15 files changed, 217 insertions(+) create mode 100644 tests/pos/t1164.scala create mode 100644 tests/pos/t1318.scala create mode 100644 tests/pos/t1385.scala create mode 100644 tests/pos/t1391.scala create mode 100644 tests/pos/t1422_pos.scala create mode 100644 tests/pos/t1438.scala create mode 100644 tests/pos/t1439.scala create mode 100644 tests/pos/t1480.scala create mode 100644 tests/pos/t151.scala create mode 100644 tests/pos/t1560.scala create mode 100644 tests/pos/t1565.scala create mode 100644 tests/pos/t1569.scala create mode 100644 tests/pos/t159.scala create mode 100644 tests/pos/t1591_pos.scala create mode 100644 tests/pos/t1591b.scala (limited to 'tests/pos') diff --git a/tests/pos/t1164.scala b/tests/pos/t1164.scala new file mode 100644 index 000000000..ab58c1d6b --- /dev/null +++ b/tests/pos/t1164.scala @@ -0,0 +1,29 @@ + + +object test { + + class Foo[a](val arg : a) + + object Foo { + def apply [a](arg : a, right :a) = new Foo[a](arg) + def unapply [a](m : Foo[a]) = Some (m.arg) + } + + def matchAndGetArgFromFoo[a]( e:Foo[a]):a = {e match { case Foo(x) => x }} + + + // Try the same thing as above but use function as argument to Bar + // constructor + + type FunIntToA [a] = (Int) => a + class Bar[a] (var f: FunIntToA[a]) + + object Bar { + def apply[a](f: FunIntToA[a]) = new Bar[a](f) + def unapply[a](m: Bar[a]) = Some (m.f) + } + + def matchAndGetFunFromBar[a](b:Bar[a]) : FunIntToA[a] = { b match { case Bar(x) => x}} + + +} diff --git a/tests/pos/t1318.scala b/tests/pos/t1318.scala new file mode 100644 index 000000000..34e2bc8dd --- /dev/null +++ b/tests/pos/t1318.scala @@ -0,0 +1,31 @@ +abstract class F { + type mType <: M +} + +abstract class M { self => + + type mType <: M + + type fType = F {type mType >: self.mType } + def fs: List[fType] +} + +abstract class A0 extends M { + type mType = A0 + def fs: List[fType] = Nil +} + +object A extends A0 {} + +abstract class B0 extends M { + type mType = B0 + def fs: List[fType] = Nil +} + +object B extends B0 {} + +object C { + def ab = List(A) ::: List(B) + // the following compiles successfully: + // def ab = List(A) ::: List[M](B) +} diff --git a/tests/pos/t1385.scala b/tests/pos/t1385.scala new file mode 100644 index 000000000..aefd9c35b --- /dev/null +++ b/tests/pos/t1385.scala @@ -0,0 +1,3 @@ +object Test extends Serializable { + private def readResolve: AnyRef = this +} diff --git a/tests/pos/t1391.scala b/tests/pos/t1391.scala new file mode 100644 index 000000000..5178ba987 --- /dev/null +++ b/tests/pos/t1391.scala @@ -0,0 +1,43 @@ +package sandbox + + class hierarOverload { + + /* + * Template structure - using abstract types. + */ + trait AB { + type TA <: A + type TB <: B + + protected trait A { + val entities : List[TB] + } + + protected trait B { + var group : TA + } + } + + /* + * Template instantiation in an object to ease use and globally define + abstract types + */ + object NAnB extends AB { + type TB = nB + type TA = nA + + class nA extends A { + val entities = List[nB]() + } + + class nB extends B { + var group = new nA + } + } + + def foo (): Unit = { + val t = new NAnB.nA + println(t) + } + + } diff --git a/tests/pos/t1422_pos.scala b/tests/pos/t1422_pos.scala new file mode 100644 index 000000000..658f5c730 --- /dev/null +++ b/tests/pos/t1422_pos.scala @@ -0,0 +1,2 @@ +case class A(private val foo:String) +case class B(protected[this] val foo:String) diff --git a/tests/pos/t1438.scala b/tests/pos/t1438.scala new file mode 100644 index 000000000..221c3439d --- /dev/null +++ b/tests/pos/t1438.scala @@ -0,0 +1,10 @@ +class C[A] { + type CC[B] <: C[B] + def aio[T]: T = aio[T] +} +class D[A] extends C[A] { + protected def nv[B](elems: Iterator[B]): CC[B] = { + val x = new D[B] + x.aio[CC[B]] + } +} diff --git a/tests/pos/t1439.scala b/tests/pos/t1439.scala new file mode 100644 index 000000000..0efcc74b6 --- /dev/null +++ b/tests/pos/t1439.scala @@ -0,0 +1,8 @@ +// no unchecked warnings +class View[C[A]] { } + +object Test { + (null: Any) match { + case v: View[_] => + } +} diff --git a/tests/pos/t1480.scala b/tests/pos/t1480.scala new file mode 100644 index 000000000..1d9f94d2e --- /dev/null +++ b/tests/pos/t1480.scala @@ -0,0 +1,6 @@ +class Foo{ + def compare(newP : Any, oldP : Any) : Boolean = (newP,oldP) match { + case (newP : AnyRef, oldP : AnyRef) if newP == oldP => newP == oldP + case (newS : Symbol, oldS: Symbol) if newS == oldS => newS == oldS + } +} diff --git a/tests/pos/t151.scala b/tests/pos/t151.scala new file mode 100644 index 000000000..86667b49f --- /dev/null +++ b/tests/pos/t151.scala @@ -0,0 +1,6 @@ +abstract class Foo { + type T; + def foo(a: T): Int = 0; + val foo: Foo = null; + def a: foo.T = a; +} diff --git a/tests/pos/t1560.scala b/tests/pos/t1560.scala new file mode 100644 index 000000000..dd76392e6 --- /dev/null +++ b/tests/pos/t1560.scala @@ -0,0 +1,13 @@ +object Test extends App { + + trait C[T] { + def t: T + } + + def b: Option[C[_]] = null + + def c = b match { + case Some(b) => b.t + } + +} diff --git a/tests/pos/t1565.scala b/tests/pos/t1565.scala new file mode 100644 index 000000000..59d27a086 --- /dev/null +++ b/tests/pos/t1565.scala @@ -0,0 +1,19 @@ +object Bug1565 { + +// object X0 { 0; (a : Int, b : Int, c : Int) => println(List(a, b)) } // can't parse in Dotty +// def x() = { 0; (a : Int, b : Int) => println(List(a, b)) ; 0 } // can't parse in Dotty + +// (a : Int, b : Int) => println(List(a, b)) not legal as a template statement + + // various function syntaxes to exercise the parser + val xs = List(1,2,3) + xs.filter(x => x < 2) + xs.filter((x) => x < 2) + xs.filter { x => x < 2 } + xs.filter { _ < 2 } + xs.filter (_ < 2) + xs.foreach { e => + val buf0 = e + 1 + buf0 + } +} diff --git a/tests/pos/t1569.scala b/tests/pos/t1569.scala new file mode 100644 index 000000000..a7200a6d1 --- /dev/null +++ b/tests/pos/t1569.scala @@ -0,0 +1,5 @@ +object Bug { + class C { type T } + def foo(x: Int)(y: C)(z: y.T): Unit = {} + foo(3)(new C { type T = String })("hello") +} diff --git a/tests/pos/t159.scala b/tests/pos/t159.scala new file mode 100644 index 000000000..4d67f8aff --- /dev/null +++ b/tests/pos/t159.scala @@ -0,0 +1,22 @@ +object foo { + // the problem seems to appear only + // if "val _" is in the body of a case + def cooked(ckd: StringBuilder): Unit = { + 'a' match { + case '-' => + val _ = ckd.append( '_' ); + case 'v' => + val _ = ckd.append( '_' ); + } + } +} + +object foo1 { + def f(): Unit = { + 1 match { + case 2 => val _ = 1; + case 3 => val _ = 2; + case 4 => val _ = 2; + } + } +} diff --git a/tests/pos/t1591_pos.scala b/tests/pos/t1591_pos.scala new file mode 100644 index 000000000..4f55d7ce1 --- /dev/null +++ b/tests/pos/t1591_pos.scala @@ -0,0 +1,7 @@ +trait A + +object Test { + lazy val a = new A { + object Zenek + } +} diff --git a/tests/pos/t1591b.scala b/tests/pos/t1591b.scala new file mode 100644 index 000000000..c671ad647 --- /dev/null +++ b/tests/pos/t1591b.scala @@ -0,0 +1,13 @@ +import scala.tools.nsc._ + +class SemanticTokens(val compiler: Global) { + import compiler._ + + def build() = ErrorType + + class Process { + def f() = analyzer + // or to crash the compiler instead of a nice message, + // def f() = analyzer underlying _ + } +} -- cgit v1.2.3 From 82c4db686d07ae8e91f157f5c8b55a1a76917941 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 5 May 2014 18:34:59 +0200 Subject: Pos tests t17xx - t19xx --- test/dotc/tests.scala | 1 + tests/disabled/java-interop/pos/t1711/Seq.scala | 12 +++++ tests/disabled/java-interop/pos/t1711/Test.java | 6 +++ tests/disabled/java-interop/pos/t1745/J.java | 10 ++++ tests/disabled/java-interop/pos/t1745/S.scala | 7 +++ tests/disabled/java-interop/pos/t1751/A1_2.scala | 2 + tests/disabled/java-interop/pos/t1751/A2_1.scala | 2 + .../java-interop/pos/t1751/SuiteClasses.java | 3 ++ tests/disabled/java-interop/pos/t1782/Ann.java | 3 ++ tests/disabled/java-interop/pos/t1782/Days.java | 3 ++ .../java-interop/pos/t1782/ImplementedBy.java | 3 ++ tests/disabled/java-interop/pos/t1782/Test_1.scala | 16 ++++++ tests/disabled/java-interop/pos/t1836/J.java | 1 + tests/disabled/java-interop/pos/t1836/S.scala | 1 + tests/disabled/java-interop/pos/t1840/J.java | 4 ++ tests/disabled/java-interop/pos/t1840/S.scala | 2 + .../java-interop/pos/t1937/NumberGenerator.java | 7 +++ tests/disabled/not-representable/pos/t1803.flags | 1 + tests/disabled/not-representable/pos/t1803.scala | 3 ++ tests/neg/t1843.scala | 25 ++++++++++ tests/new/t160.scala | 3 -- tests/new/t1642b.scala | 6 --- tests/new/t1659.scala | 4 -- tests/new/t1675.scala | 11 ----- tests/pending/pos/t1756.scala | 54 ++++++++++++++++++++ tests/pending/pos/t1832.scala | 10 ++++ tests/pos/t160.scala | 3 ++ tests/pos/t1642b.scala | 6 +++ tests/pos/t1659.scala | 4 ++ tests/pos/t1675.scala | 11 +++++ tests/pos/t1722-A.scala | 10 ++++ tests/pos/t1722/Test.scala | 5 ++ tests/pos/t1722/Top.scala | 13 +++++ tests/pos/t175.scala | 3 ++ tests/pos/t177.scala | 8 +++ tests/pos/t1785.scala | 7 +++ tests/pos/t1786-counter.scala | 38 +++++++++++++++ tests/pos/t1786-cycle.scala | 57 ++++++++++++++++++++++ tests/pos/t1789.scala | 5 ++ tests/pos/t1798.scala | 10 ++++ tests/pos/t183.scala | 4 ++ tests/pos/t1843.scala | 25 ++++++++++ tests/pos/t1858.scala | 13 +++++ tests/pos/t1896/D0.scala | 11 +++++ tests/pos/t1896/D1.scala | 2 + tests/pos/t1942/A_1.scala | 11 +++++ tests/pos/t1942/Test_2.scala | 3 ++ tests/pos/t1957.scala | 38 +++++++++++++++ tests/pos/t1974.scala | 20 ++++++++ tests/pos/t1987a.scala | 8 +++ tests/pos/t1987b/a.scala | 7 +++ tests/pos/t1987b/b.scala | 10 ++++ tests/pos/t1996.scala | 19 ++++++++ tests/untried/pos/t1711/Seq.scala | 12 ----- tests/untried/pos/t1711/Test.java | 6 --- tests/untried/pos/t1722-A.scala | 10 ---- tests/untried/pos/t1722/Test.scala | 5 -- tests/untried/pos/t1722/Top.scala | 13 ----- tests/untried/pos/t1745/J.java | 10 ---- tests/untried/pos/t1745/S.scala | 7 --- tests/untried/pos/t175.scala | 3 -- tests/untried/pos/t1751/A1_2.scala | 2 - tests/untried/pos/t1751/A2_1.scala | 2 - tests/untried/pos/t1751/SuiteClasses.java | 3 -- tests/untried/pos/t1756.scala | 54 -------------------- tests/untried/pos/t177.scala | 8 --- tests/untried/pos/t1782/Ann.java | 3 -- tests/untried/pos/t1782/Days.java | 3 -- tests/untried/pos/t1782/ImplementedBy.java | 3 -- tests/untried/pos/t1782/Test_1.scala | 16 ------ tests/untried/pos/t1785.scala | 7 --- tests/untried/pos/t1786-counter.scala | 38 --------------- tests/untried/pos/t1786-cycle.scala | 57 ---------------------- tests/untried/pos/t1789.scala | 5 -- tests/untried/pos/t1798.scala | 10 ---- tests/untried/pos/t1803.flags | 1 - tests/untried/pos/t1803.scala | 2 - tests/untried/pos/t183.scala | 4 -- tests/untried/pos/t1832.scala | 8 --- tests/untried/pos/t1836/J.java | 1 - tests/untried/pos/t1836/S.scala | 1 - tests/untried/pos/t1840/J.java | 4 -- tests/untried/pos/t1840/S.scala | 2 - tests/untried/pos/t1843.scala | 25 ---------- tests/untried/pos/t1858.scala | 13 ----- tests/untried/pos/t1896/D0.scala | 11 ----- tests/untried/pos/t1896/D1.scala | 2 - tests/untried/pos/t1937/NumberGenerator.java | 7 --- tests/untried/pos/t1942/A_1.scala | 11 ----- tests/untried/pos/t1942/Test_2.scala | 3 -- tests/untried/pos/t1957.scala | 38 --------------- tests/untried/pos/t1974.scala | 20 -------- tests/untried/pos/t1987a.scala | 8 --- tests/untried/pos/t1987b/a.scala | 7 --- tests/untried/pos/t1987b/b.scala | 10 ---- tests/untried/pos/t1996.scala | 19 -------- 96 files changed, 527 insertions(+), 498 deletions(-) create mode 100644 tests/disabled/java-interop/pos/t1711/Seq.scala create mode 100644 tests/disabled/java-interop/pos/t1711/Test.java create mode 100644 tests/disabled/java-interop/pos/t1745/J.java create mode 100644 tests/disabled/java-interop/pos/t1745/S.scala create mode 100644 tests/disabled/java-interop/pos/t1751/A1_2.scala create mode 100644 tests/disabled/java-interop/pos/t1751/A2_1.scala create mode 100644 tests/disabled/java-interop/pos/t1751/SuiteClasses.java create mode 100644 tests/disabled/java-interop/pos/t1782/Ann.java create mode 100644 tests/disabled/java-interop/pos/t1782/Days.java create mode 100644 tests/disabled/java-interop/pos/t1782/ImplementedBy.java create mode 100644 tests/disabled/java-interop/pos/t1782/Test_1.scala create mode 100644 tests/disabled/java-interop/pos/t1836/J.java create mode 100644 tests/disabled/java-interop/pos/t1836/S.scala create mode 100644 tests/disabled/java-interop/pos/t1840/J.java create mode 100644 tests/disabled/java-interop/pos/t1840/S.scala create mode 100644 tests/disabled/java-interop/pos/t1937/NumberGenerator.java create mode 100644 tests/disabled/not-representable/pos/t1803.flags create mode 100644 tests/disabled/not-representable/pos/t1803.scala create mode 100644 tests/neg/t1843.scala delete mode 100644 tests/new/t160.scala delete mode 100644 tests/new/t1642b.scala delete mode 100644 tests/new/t1659.scala delete mode 100644 tests/new/t1675.scala create mode 100755 tests/pending/pos/t1756.scala create mode 100644 tests/pending/pos/t1832.scala create mode 100644 tests/pos/t160.scala create mode 100644 tests/pos/t1642b.scala create mode 100644 tests/pos/t1659.scala create mode 100644 tests/pos/t1675.scala create mode 100644 tests/pos/t1722-A.scala create mode 100755 tests/pos/t1722/Test.scala create mode 100755 tests/pos/t1722/Top.scala create mode 100644 tests/pos/t175.scala create mode 100644 tests/pos/t177.scala create mode 100644 tests/pos/t1785.scala create mode 100644 tests/pos/t1786-counter.scala create mode 100644 tests/pos/t1786-cycle.scala create mode 100644 tests/pos/t1789.scala create mode 100644 tests/pos/t1798.scala create mode 100644 tests/pos/t183.scala create mode 100644 tests/pos/t1843.scala create mode 100644 tests/pos/t1858.scala create mode 100644 tests/pos/t1896/D0.scala create mode 100644 tests/pos/t1896/D1.scala create mode 100644 tests/pos/t1942/A_1.scala create mode 100644 tests/pos/t1942/Test_2.scala create mode 100644 tests/pos/t1957.scala create mode 100644 tests/pos/t1974.scala create mode 100644 tests/pos/t1987a.scala create mode 100644 tests/pos/t1987b/a.scala create mode 100644 tests/pos/t1987b/b.scala create mode 100644 tests/pos/t1996.scala delete mode 100644 tests/untried/pos/t1711/Seq.scala delete mode 100644 tests/untried/pos/t1711/Test.java delete mode 100644 tests/untried/pos/t1722-A.scala delete mode 100755 tests/untried/pos/t1722/Test.scala delete mode 100755 tests/untried/pos/t1722/Top.scala delete mode 100644 tests/untried/pos/t1745/J.java delete mode 100644 tests/untried/pos/t1745/S.scala delete mode 100644 tests/untried/pos/t175.scala delete mode 100644 tests/untried/pos/t1751/A1_2.scala delete mode 100644 tests/untried/pos/t1751/A2_1.scala delete mode 100644 tests/untried/pos/t1751/SuiteClasses.java delete mode 100755 tests/untried/pos/t1756.scala delete mode 100644 tests/untried/pos/t177.scala delete mode 100644 tests/untried/pos/t1782/Ann.java delete mode 100644 tests/untried/pos/t1782/Days.java delete mode 100644 tests/untried/pos/t1782/ImplementedBy.java delete mode 100644 tests/untried/pos/t1782/Test_1.scala delete mode 100644 tests/untried/pos/t1785.scala delete mode 100644 tests/untried/pos/t1786-counter.scala delete mode 100644 tests/untried/pos/t1786-cycle.scala delete mode 100644 tests/untried/pos/t1789.scala delete mode 100644 tests/untried/pos/t1798.scala delete mode 100644 tests/untried/pos/t1803.flags delete mode 100644 tests/untried/pos/t1803.scala delete mode 100644 tests/untried/pos/t183.scala delete mode 100644 tests/untried/pos/t1832.scala delete mode 100644 tests/untried/pos/t1836/J.java delete mode 100644 tests/untried/pos/t1836/S.scala delete mode 100644 tests/untried/pos/t1840/J.java delete mode 100644 tests/untried/pos/t1840/S.scala delete mode 100644 tests/untried/pos/t1843.scala delete mode 100644 tests/untried/pos/t1858.scala delete mode 100644 tests/untried/pos/t1896/D0.scala delete mode 100644 tests/untried/pos/t1896/D1.scala delete mode 100644 tests/untried/pos/t1937/NumberGenerator.java delete mode 100644 tests/untried/pos/t1942/A_1.scala delete mode 100644 tests/untried/pos/t1942/Test_2.scala delete mode 100644 tests/untried/pos/t1957.scala delete mode 100644 tests/untried/pos/t1974.scala delete mode 100644 tests/untried/pos/t1987a.scala delete mode 100644 tests/untried/pos/t1987b/a.scala delete mode 100644 tests/untried/pos/t1987b/b.scala delete mode 100644 tests/untried/pos/t1996.scala (limited to 'tests/pos') diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 31ab15b57..9a173a5ce 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -83,6 +83,7 @@ class tests extends CompilerTest { @Test def neg_tailcall = compileFile(negDir, "tailcall/tailrec", xerrors = 7) @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 dotc = compileDir(dotcDir + "tools/dotc", twice) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) diff --git a/tests/disabled/java-interop/pos/t1711/Seq.scala b/tests/disabled/java-interop/pos/t1711/Seq.scala new file mode 100644 index 000000000..c18f05cd7 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1711/Seq.scala @@ -0,0 +1,12 @@ +package com + +object Sequence { + + def filteringFunction[V](filter: V => Boolean): List[V] => List[V] = { + def include(v: V) = + filter(v) + (l: List[V]) => l.filter(include) + } + +} + diff --git a/tests/disabled/java-interop/pos/t1711/Test.java b/tests/disabled/java-interop/pos/t1711/Test.java new file mode 100644 index 000000000..5ec0f2297 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1711/Test.java @@ -0,0 +1,6 @@ +import com.Sequence; + +public class Test { + void foo() { + } +} diff --git a/tests/disabled/java-interop/pos/t1745/J.java b/tests/disabled/java-interop/pos/t1745/J.java new file mode 100644 index 000000000..8444eabb2 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1745/J.java @@ -0,0 +1,10 @@ +class J { + S1 s1; + S2 s2; + + String s = bar(S3.foo(), S3.bar("def")); + + private String bar(String s1, String s2) { + return s1 + s2; + } +} diff --git a/tests/disabled/java-interop/pos/t1745/S.scala b/tests/disabled/java-interop/pos/t1745/S.scala new file mode 100644 index 000000000..84c437133 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1745/S.scala @@ -0,0 +1,7 @@ +case class S1(n: Int) { } +case class S2(n: Int, p: Int) { } +class S3 { } +object S3 { + def foo() = "abc" + def bar[T](x: T): T = x +} diff --git a/tests/disabled/java-interop/pos/t1751/A1_2.scala b/tests/disabled/java-interop/pos/t1751/A1_2.scala new file mode 100644 index 000000000..354d5eecd --- /dev/null +++ b/tests/disabled/java-interop/pos/t1751/A1_2.scala @@ -0,0 +1,2 @@ +@SuiteClasses(Array(classOf[A2])) +class A1 diff --git a/tests/disabled/java-interop/pos/t1751/A2_1.scala b/tests/disabled/java-interop/pos/t1751/A2_1.scala new file mode 100644 index 000000000..c768062e4 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1751/A2_1.scala @@ -0,0 +1,2 @@ +@SuiteClasses(Array()) +class A2 diff --git a/tests/disabled/java-interop/pos/t1751/SuiteClasses.java b/tests/disabled/java-interop/pos/t1751/SuiteClasses.java new file mode 100644 index 000000000..a415e4f57 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1751/SuiteClasses.java @@ -0,0 +1,3 @@ +public @interface SuiteClasses { + public Class[] value(); +} diff --git a/tests/disabled/java-interop/pos/t1782/Ann.java b/tests/disabled/java-interop/pos/t1782/Ann.java new file mode 100644 index 000000000..0dcfbd2ed --- /dev/null +++ b/tests/disabled/java-interop/pos/t1782/Ann.java @@ -0,0 +1,3 @@ +public @interface Ann { + public Days value(); +} diff --git a/tests/disabled/java-interop/pos/t1782/Days.java b/tests/disabled/java-interop/pos/t1782/Days.java new file mode 100644 index 000000000..203a87b1c --- /dev/null +++ b/tests/disabled/java-interop/pos/t1782/Days.java @@ -0,0 +1,3 @@ +public enum Days { + Friday, Sunday +} diff --git a/tests/disabled/java-interop/pos/t1782/ImplementedBy.java b/tests/disabled/java-interop/pos/t1782/ImplementedBy.java new file mode 100644 index 000000000..6aa8b4fa9 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1782/ImplementedBy.java @@ -0,0 +1,3 @@ +public @interface ImplementedBy { + public Class value(); +} diff --git a/tests/disabled/java-interop/pos/t1782/Test_1.scala b/tests/disabled/java-interop/pos/t1782/Test_1.scala new file mode 100644 index 000000000..6467a74c2 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1782/Test_1.scala @@ -0,0 +1,16 @@ +@ImplementedBy(classOf[Provider]) +trait Service { + def someMethod() +} + +class Provider + extends Service +{ + // test enumeration java annotations + @Ann(Days.Friday) def someMethod() = () + + // #2103 + @scala.beans.BeanProperty + @Ann(value = Days.Sunday) + val t2103 = "test" +} diff --git a/tests/disabled/java-interop/pos/t1836/J.java b/tests/disabled/java-interop/pos/t1836/J.java new file mode 100644 index 000000000..a009a59e2 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1836/J.java @@ -0,0 +1 @@ +public abstract class J { protected J(T id) { } } diff --git a/tests/disabled/java-interop/pos/t1836/S.scala b/tests/disabled/java-interop/pos/t1836/S.scala new file mode 100644 index 000000000..88ce1063e --- /dev/null +++ b/tests/disabled/java-interop/pos/t1836/S.scala @@ -0,0 +1 @@ +class S extends J("") diff --git a/tests/disabled/java-interop/pos/t1840/J.java b/tests/disabled/java-interop/pos/t1840/J.java new file mode 100644 index 000000000..fd98b6c4a --- /dev/null +++ b/tests/disabled/java-interop/pos/t1840/J.java @@ -0,0 +1,4 @@ +package p; +class J { + J() {} +} diff --git a/tests/disabled/java-interop/pos/t1840/S.scala b/tests/disabled/java-interop/pos/t1840/S.scala new file mode 100644 index 000000000..ff513d2c1 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1840/S.scala @@ -0,0 +1,2 @@ +package p +class S { new J } diff --git a/tests/disabled/java-interop/pos/t1937/NumberGenerator.java b/tests/disabled/java-interop/pos/t1937/NumberGenerator.java new file mode 100644 index 000000000..59d604733 --- /dev/null +++ b/tests/disabled/java-interop/pos/t1937/NumberGenerator.java @@ -0,0 +1,7 @@ +package br.com.caelum.caelumweb2.money; + +public class NumberGenerator { + public String generate() { + return null; + } +} diff --git a/tests/disabled/not-representable/pos/t1803.flags b/tests/disabled/not-representable/pos/t1803.flags new file mode 100644 index 000000000..d1a824416 --- /dev/null +++ b/tests/disabled/not-representable/pos/t1803.flags @@ -0,0 +1 @@ +-Yinfer-argument-types \ No newline at end of file diff --git a/tests/disabled/not-representable/pos/t1803.scala b/tests/disabled/not-representable/pos/t1803.scala new file mode 100644 index 000000000..94b59a480 --- /dev/null +++ b/tests/disabled/not-representable/pos/t1803.scala @@ -0,0 +1,3 @@ +// No parameter type inference in Dotty +class A { def foo[A](a: A) = a } +class B extends A { override def foo[A](b) = b } diff --git a/tests/neg/t1843.scala b/tests/neg/t1843.scala new file mode 100644 index 000000000..8504bf342 --- /dev/null +++ b/tests/neg/t1843.scala @@ -0,0 +1,25 @@ +/** +* Scala Compiler Will Crash On this File +* ... Or Will It? +* +*/ + +object Crash { + trait UpdateType[A] + case class StateUpdate[A](updateType : UpdateType[A], value : A) + case object IntegerUpdateType extends UpdateType[Integer] + + //However this method will cause a crash + def crash(updates: List[StateUpdate[_]]): Unit = { + updates match { + case Nil => + case u::us => + u match { + //Line below seems to be the crashing line + case StateUpdate(key, newValue) if (key == IntegerUpdateType) => + println("Requires a statement to induce the crash") + case _ => + } + } + } +} diff --git a/tests/new/t160.scala b/tests/new/t160.scala deleted file mode 100644 index 91ac2ba84..000000000 --- a/tests/new/t160.scala +++ /dev/null @@ -1,3 +0,0 @@ -class Foo(s:String) { - def this() = { this("DEFAULT") } -} diff --git a/tests/new/t1642b.scala b/tests/new/t1642b.scala deleted file mode 100644 index 72e53b0c9..000000000 --- a/tests/new/t1642b.scala +++ /dev/null @@ -1,6 +0,0 @@ -package x -abstract class H[A] { - type P <: R[P] - def a: P -} -class R[F] diff --git a/tests/new/t1659.scala b/tests/new/t1659.scala deleted file mode 100644 index 10470d66f..000000000 --- a/tests/new/t1659.scala +++ /dev/null @@ -1,4 +0,0 @@ -trait Y { type X } -trait W { def u[A](v : Y { type X = A }) : Unit } -class Z extends W { def u[A](v : Y { type X = A }) = null } - diff --git a/tests/new/t1675.scala b/tests/new/t1675.scala deleted file mode 100644 index 8630890ee..000000000 --- a/tests/new/t1675.scala +++ /dev/null @@ -1,11 +0,0 @@ -package a -object Foo extends pack.Bar { - for(i <- 0 to 10) { - test("") - } -} -package pack { - class Bar { - protected def test(s: String*): Unit = {} - } -} diff --git a/tests/pending/pos/t1756.scala b/tests/pending/pos/t1756.scala new file mode 100755 index 000000000..1d067c3b0 --- /dev/null +++ b/tests/pending/pos/t1756.scala @@ -0,0 +1,54 @@ + +/** +This is a tricky issue which has to do with the fact that too much conflicting +type information is propagated into a single implicit search, where the intended +solution applies two implicit searches. + +Roughly, in x + x * y, the first x is first typed as Poly[A]. That +means the x * y is then typed as Poly[A]. Then the second x is typed +as Poly[A], then y is typed as Poly[Poly[A]]. The application x * y +fails, so the coef2poly implicit conversion is applied to x. That +means we look for an implicit conversion from type Poly[A] to type +?{val *(x$1: ?>: Poly[Poly[A]] <: Any): Poly[A]}. Note that the result +type Poly[A] is propagated into the implicit search. Poly[A] comes as +expected type from x+, because the lhs x is still typed as a Poly[A]. +This means that the argument of the implicit conversion is typechecked +with expected type A with Poly[A]. And no solution is found. + +To solve this, I added a fallback scheme similar to implicit arguments: +When an implicit view that adds a method matching given arguments and result +type fails, try again without the result type. +*/ +trait Ring[T <: Ring[T]] { + def +(that: T): T + def *(that: T): T +} + +class A extends Ring[A] { + def +(that: A) = new A + def *(that: A) = new A +} + +class Poly[C <: Ring[C]](val c: C) extends Ring[Poly[C]] { + def +(that: Poly[C]) = new Poly(this.c+that.c) + def *(that: Poly[C]) = new Poly(this.c*that.c) +} + +object Test extends App { + + implicit def coef2poly[C <: Ring[C]](c: C): Poly[C] = new Poly(c) + + val a = new A + val x = new Poly(new A) + + println(x+a) // works + println(a+x) // works + + val y = new Poly(new Poly(new A)) + + println(x+y*x) // works + println(x*y+x) // works + println(y*x+x) // works + + println(x+x*y) // failed before +} diff --git a/tests/pending/pos/t1832.scala b/tests/pending/pos/t1832.scala new file mode 100644 index 000000000..9ad9703c2 --- /dev/null +++ b/tests/pending/pos/t1832.scala @@ -0,0 +1,10 @@ +trait Cloning { + trait Foo + def fn(g: Any => Unit): Foo + + class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo } + + implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null } + + val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } +} diff --git a/tests/pos/t160.scala b/tests/pos/t160.scala new file mode 100644 index 000000000..91ac2ba84 --- /dev/null +++ b/tests/pos/t160.scala @@ -0,0 +1,3 @@ +class Foo(s:String) { + def this() = { this("DEFAULT") } +} diff --git a/tests/pos/t1642b.scala b/tests/pos/t1642b.scala new file mode 100644 index 000000000..72e53b0c9 --- /dev/null +++ b/tests/pos/t1642b.scala @@ -0,0 +1,6 @@ +package x +abstract class H[A] { + type P <: R[P] + def a: P +} +class R[F] diff --git a/tests/pos/t1659.scala b/tests/pos/t1659.scala new file mode 100644 index 000000000..10470d66f --- /dev/null +++ b/tests/pos/t1659.scala @@ -0,0 +1,4 @@ +trait Y { type X } +trait W { def u[A](v : Y { type X = A }) : Unit } +class Z extends W { def u[A](v : Y { type X = A }) = null } + diff --git a/tests/pos/t1675.scala b/tests/pos/t1675.scala new file mode 100644 index 000000000..8630890ee --- /dev/null +++ b/tests/pos/t1675.scala @@ -0,0 +1,11 @@ +package a +object Foo extends pack.Bar { + for(i <- 0 to 10) { + test("") + } +} +package pack { + class Bar { + protected def test(s: String*): Unit = {} + } +} diff --git a/tests/pos/t1722-A.scala b/tests/pos/t1722-A.scala new file mode 100644 index 000000000..d059bf22f --- /dev/null +++ b/tests/pos/t1722-A.scala @@ -0,0 +1,10 @@ +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +*/ diff --git a/tests/pos/t1722/Test.scala b/tests/pos/t1722/Test.scala new file mode 100755 index 000000000..f236d3fdc --- /dev/null +++ b/tests/pos/t1722/Test.scala @@ -0,0 +1,5 @@ +package t1722 + +object Test { + val x = new AnyRef with C +} diff --git a/tests/pos/t1722/Top.scala b/tests/pos/t1722/Top.scala new file mode 100755 index 000000000..4ac52412a --- /dev/null +++ b/tests/pos/t1722/Top.scala @@ -0,0 +1,13 @@ +package t1722 + +sealed trait Top +trait C { + private object P extends Top +} +/* +$ scala -e 'new AnyRef with C' +error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken +(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) +one error found +Martin: I think this has to do with children property. +*/ diff --git a/tests/pos/t175.scala b/tests/pos/t175.scala new file mode 100644 index 000000000..4c0eb28ba --- /dev/null +++ b/tests/pos/t175.scala @@ -0,0 +1,3 @@ +abstract class C { + def this(x: Unit) = { this() } +} diff --git a/tests/pos/t177.scala b/tests/pos/t177.scala new file mode 100644 index 000000000..33b4de926 --- /dev/null +++ b/tests/pos/t177.scala @@ -0,0 +1,8 @@ +class A { + def foo = { + object Y { + def bar = 1; + } + Y.bar + } +} diff --git a/tests/pos/t1785.scala b/tests/pos/t1785.scala new file mode 100644 index 000000000..0b1fafb27 --- /dev/null +++ b/tests/pos/t1785.scala @@ -0,0 +1,7 @@ +class t1785 { + def apply[T](x: Int) = 1 +} + +object test { + (new t1785)[Int](1) +} diff --git a/tests/pos/t1786-counter.scala b/tests/pos/t1786-counter.scala new file mode 100644 index 000000000..a2431343d --- /dev/null +++ b/tests/pos/t1786-counter.scala @@ -0,0 +1,38 @@ +trait ShapeLevel + +object Fail { + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } + + trait ShapeLevel +} + +object Ok { + abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] + + abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] + } + + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? + } +} + +// This is why we reverted the fix for SI-1786 -- see SI-6169 for a potential alternative that could be extended to cover this. +// both objects type check on 2.10.3, but only Ok was accepted by 2.11 after the original fix to SI-1786. +// Fail results in: +/* +t1786-counter.scala:10: error: class TupleShape needs to be abstract, since method copy in class ProductNodeShape of type (shapes: Seq[Fail.Shape[_, _, _, _]])Fail.Shape[Level, _, _, _] is not defined +(Note that Seq[Fail.Shape[_, _, _, _]] does not match Seq[Fail.Shape[_ <: Fail.ShapeLevel, _, _, _]]: their type parameters differ) + final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { + ^ +one error found +*/ diff --git a/tests/pos/t1786-cycle.scala b/tests/pos/t1786-cycle.scala new file mode 100644 index 000000000..9de149fbc --- /dev/null +++ b/tests/pos/t1786-cycle.scala @@ -0,0 +1,57 @@ +trait GenTraversableLike[+A, +Repr] extends Any + +object O { + (null: Any) match { + case _: LongTraversableLike[_] => + } +} + +trait LongTraversable extends LongTraversableLike[LongTraversable] + +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + +/* +% scalac-hash v2.11.0-M8 test/files/pos/t1786-cycle.scala +[warn] v2.11.0-M8 failed, using closest available +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] + ^ +one error found + +Okay again after SI-1786 was reverted. + + +|-- object O BYVALmode-EXPRmode (site: package ) +| |-- super EXPRmode-POLYmode-QUALmode (silent: in O) +| | |-- this EXPRmode (silent: in O) +| | | \-> O.type +| | \-> O.type +| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ in O) +| | |-- (null: Any) BYVALmode-EXPRmode (site: value in O) +| | | |-- Any TYPEmode (site: value in O) +| | | | \-> Any +| | | |-- null : pt=Any EXPRmode (site: value in O) +| | | | \-> Null(null) +| | | \-> Any +| | |-- (_: LongTraversableLike[(_ @ )]) : pt=Any PATTERNmode (site: value in O) enrichment only +| | | |-- LongTraversableLike[(_ @ )] TYPEPATmode-TYPEmode (site: value in O) enrichment only +| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in ) +| | | | | | |-- Repr NOmode (site: type Repr in ) +| | | | | | | \-> Repr +| | | | | | \-> LongTraversableLike[Repr] +| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) +| | | | | \-> <: LongTraversableLike[Repr] +| | | | |-- (_ @ ) TYPEPATmode-TYPEmode (site: value in O) enrichment only +| | | | | \-> _ +| | | | |-- GenTraversableLike FUNmode-TYPEmode (site: trait LongTraversableLike) +| | | | | \-> GenTraversableLike +| | | | |-- GenTraversableLike[Any, Repr] TYPEmode (site: trait LongTraversableLike) +| | | | | |-- Any TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Any +| | | | | |-- Repr TYPEmode (site: trait LongTraversableLike) +| | | | | | \-> Repr +| | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving trait LongTraversableLike: while typing GenTraversableLike[Any, Repr] +test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike +trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenT +*/ diff --git a/tests/pos/t1789.scala b/tests/pos/t1789.scala new file mode 100644 index 000000000..1a37d48d0 --- /dev/null +++ b/tests/pos/t1789.scala @@ -0,0 +1,5 @@ +object S { + try { } + catch { case _ => } + finally { while(true) { } } +} diff --git a/tests/pos/t1798.scala b/tests/pos/t1798.scala new file mode 100644 index 000000000..1624e3025 --- /dev/null +++ b/tests/pos/t1798.scala @@ -0,0 +1,10 @@ +object Foo { private def bar(): Int = 55 } +class Foo(x: Int) { def this() = this(Foo.bar()) } + +/* + * scalac28 a.scala +a.scala:2: error: method bar cannot be accessed in object Foo +class Foo(x: Int) { def this() = this(Foo.bar()) } + ^ +one error found +*/ diff --git a/tests/pos/t183.scala b/tests/pos/t183.scala new file mode 100644 index 000000000..d7ed27f73 --- /dev/null +++ b/tests/pos/t183.scala @@ -0,0 +1,4 @@ +object Test { + new Foo(0); + class Foo(x: Int); +} diff --git a/tests/pos/t1843.scala b/tests/pos/t1843.scala new file mode 100644 index 000000000..e9b5c5d2d --- /dev/null +++ b/tests/pos/t1843.scala @@ -0,0 +1,25 @@ +/** +* Scala Compiler Will Crash On this File +* ... Or Will It? +* +*/ + +object Crash { + trait UpdateType[A] + case class StateUpdate[+A](updateType : UpdateType[A], value : A) + case object IntegerUpdateType extends UpdateType[Integer] + + //However this method will cause a crash + def crash(updates: List[StateUpdate[_]]): Unit = { + updates match { + case Nil => + case u::us => + u match { + //Line below seems to be the crashing line + case StateUpdate(key, newValue) if (key == IntegerUpdateType) => + println("Requires a statement to induce the crash") + case _ => + } + } + } +} diff --git a/tests/pos/t1858.scala b/tests/pos/t1858.scala new file mode 100644 index 000000000..c06e73e7e --- /dev/null +++ b/tests/pos/t1858.scala @@ -0,0 +1,13 @@ +import scala.collection.immutable.Stack + +object Test { + + def test = { + val s = new Stack[Int] + s.push(1) + s.push(1, 2) + s.push(1, 2, 3) + s.push(1, 2, 3, 4) + } + +} diff --git a/tests/pos/t1896/D0.scala b/tests/pos/t1896/D0.scala new file mode 100644 index 000000000..6b3150d96 --- /dev/null +++ b/tests/pos/t1896/D0.scala @@ -0,0 +1,11 @@ +package p + +class X[T] + +trait A { + def m(s:X[_]): Unit = {} +} + +trait B extends A { + def f: Unit = { super.m(null) } +} diff --git a/tests/pos/t1896/D1.scala b/tests/pos/t1896/D1.scala new file mode 100644 index 000000000..e1ab50679 --- /dev/null +++ b/tests/pos/t1896/D1.scala @@ -0,0 +1,2 @@ +package p +class C extends B diff --git a/tests/pos/t1942/A_1.scala b/tests/pos/t1942/A_1.scala new file mode 100644 index 000000000..4915b54a6 --- /dev/null +++ b/tests/pos/t1942/A_1.scala @@ -0,0 +1,11 @@ +class A { + def foo(x: Int) = 0 + def foo(x: String) = 1 +} + +class ann(x: Int) extends annotation.StaticAnnotation + +class t { + val a = new A + @ann(a.foo(1)) def bar = 1 +} diff --git a/tests/pos/t1942/Test_2.scala b/tests/pos/t1942/Test_2.scala new file mode 100644 index 000000000..6c045bbce --- /dev/null +++ b/tests/pos/t1942/Test_2.scala @@ -0,0 +1,3 @@ +class Test { + println(new t) +} diff --git a/tests/pos/t1957.scala b/tests/pos/t1957.scala new file mode 100644 index 000000000..711ce17de --- /dev/null +++ b/tests/pos/t1957.scala @@ -0,0 +1,38 @@ +object Test { + abstract class Settings {} + + abstract class Grist + { self => + type settingsType <: Settings + type moduleType <: Module {type settingsType = self.settingsType} + val module: moduleType + } + + abstract class Tool + { self => + type settingsType <: Settings + type moduleType = Module { type settingsType = self.settingsType } + type gristType = Grist { type moduleType <: self.moduleType; type settingsType <: self.settingsType } + + def inputGrist: List[gristType] + } + + abstract class Module + { self => + type settingsType <: Settings + final type commonModuleType = Module {type settingsType = self.settingsType} + type selfType >: self.type <: commonModuleType + + // BTW: if we use the commented out type decls, the code compiles successfully + // type gristType = Grist {type settingsType <: self.settingsType; type moduleType <: commonModuleType } + + val tools: List[Tool {type settingsType = self.settingsType}] + + protected def f: List[commonModuleType] = + { + val inputGrists = tools.flatMap(_.inputGrist) // val inputGrists: List[gristType] = + inputGrists.map(_.module) + } + + } +} diff --git a/tests/pos/t1974.scala b/tests/pos/t1974.scala new file mode 100644 index 000000000..3f4d41e7f --- /dev/null +++ b/tests/pos/t1974.scala @@ -0,0 +1,20 @@ +object Broken { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += (c -> s) + def fetch(c : Class[_]) = map(c) +} + +object Works { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c, s)) + def fetch(c : Class[_]) = map(c) +} + +object Works2 { + private var map = Map[Class[_], String]() + + def addToMap(c : Class[_], s : String) = map += ((c : Class[_]) -> s) + def fetch(c : Class[_]) = map(c) +} diff --git a/tests/pos/t1987a.scala b/tests/pos/t1987a.scala new file mode 100644 index 000000000..ccab13371 --- /dev/null +++ b/tests/pos/t1987a.scala @@ -0,0 +1,8 @@ +package object overloading { + def bar(f: (Int) => Unit): Unit = () + def bar(f: (Int, Int) => Unit): Unit = () +} + +class PackageObjectOverloadingTest { + overloading.bar( (i: Int) => () ) // doesn't compile. +} diff --git a/tests/pos/t1987b/a.scala b/tests/pos/t1987b/a.scala new file mode 100644 index 000000000..ff27044b6 --- /dev/null +++ b/tests/pos/t1987b/a.scala @@ -0,0 +1,7 @@ +package bug + +// goes with t1987b.scala +package object packageb { + def func(a: Int) = () + def func(a: String) = () +} diff --git a/tests/pos/t1987b/b.scala b/tests/pos/t1987b/b.scala new file mode 100644 index 000000000..a469ca6ea --- /dev/null +++ b/tests/pos/t1987b/b.scala @@ -0,0 +1,10 @@ +// compile with t1987a.scala + +package bug.packageb +// Note that the overloading works if instead of being in the package we import it: +// replace the above line with import bug.packageb._ + +class Client { + val x = func(1) // doesn't compile: type mismatch; found: Int(1) required: String + val y = func("1") // compiles +} diff --git a/tests/pos/t1996.scala b/tests/pos/t1996.scala new file mode 100644 index 000000000..273012819 --- /dev/null +++ b/tests/pos/t1996.scala @@ -0,0 +1,19 @@ +object forbug { + val l1 = List(List(ValDef(new A)), List(ValDef(new A))) + for ((e1s, e2s) <- l1.zip(l1); + (e1, e2) <- e1s.zip(e2s)) { + e1.a.doSome(20) +// () + } +} + + +class A { + def doSome(a: Int): this.type = { + println(a) + this + } +} + +case class ValDef(a: A) + diff --git a/tests/untried/pos/t1711/Seq.scala b/tests/untried/pos/t1711/Seq.scala deleted file mode 100644 index c18f05cd7..000000000 --- a/tests/untried/pos/t1711/Seq.scala +++ /dev/null @@ -1,12 +0,0 @@ -package com - -object Sequence { - - def filteringFunction[V](filter: V => Boolean): List[V] => List[V] = { - def include(v: V) = - filter(v) - (l: List[V]) => l.filter(include) - } - -} - diff --git a/tests/untried/pos/t1711/Test.java b/tests/untried/pos/t1711/Test.java deleted file mode 100644 index 5ec0f2297..000000000 --- a/tests/untried/pos/t1711/Test.java +++ /dev/null @@ -1,6 +0,0 @@ -import com.Sequence; - -public class Test { - void foo() { - } -} diff --git a/tests/untried/pos/t1722-A.scala b/tests/untried/pos/t1722-A.scala deleted file mode 100644 index d059bf22f..000000000 --- a/tests/untried/pos/t1722-A.scala +++ /dev/null @@ -1,10 +0,0 @@ -sealed trait Top -trait C { - private object P extends Top -} -/* -$ scala -e 'new AnyRef with C' -error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken -(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) -one error found -*/ diff --git a/tests/untried/pos/t1722/Test.scala b/tests/untried/pos/t1722/Test.scala deleted file mode 100755 index f236d3fdc..000000000 --- a/tests/untried/pos/t1722/Test.scala +++ /dev/null @@ -1,5 +0,0 @@ -package t1722 - -object Test { - val x = new AnyRef with C -} diff --git a/tests/untried/pos/t1722/Top.scala b/tests/untried/pos/t1722/Top.scala deleted file mode 100755 index 4ac52412a..000000000 --- a/tests/untried/pos/t1722/Top.scala +++ /dev/null @@ -1,13 +0,0 @@ -package t1722 - -sealed trait Top -trait C { - private object P extends Top -} -/* -$ scala -e 'new AnyRef with C' -error: error while loading Top, class file '/private/tmp/bobobo/./Top.class' is broken -(error reading Scala signature of /private/tmp/bobobo/./Top.class: malformed Scala signature of Top at 185; reference value P of trait C refers to nonexisting symbol.) -one error found -Martin: I think this has to do with children property. -*/ diff --git a/tests/untried/pos/t1745/J.java b/tests/untried/pos/t1745/J.java deleted file mode 100644 index 8444eabb2..000000000 --- a/tests/untried/pos/t1745/J.java +++ /dev/null @@ -1,10 +0,0 @@ -class J { - S1 s1; - S2 s2; - - String s = bar(S3.foo(), S3.bar("def")); - - private String bar(String s1, String s2) { - return s1 + s2; - } -} diff --git a/tests/untried/pos/t1745/S.scala b/tests/untried/pos/t1745/S.scala deleted file mode 100644 index 84c437133..000000000 --- a/tests/untried/pos/t1745/S.scala +++ /dev/null @@ -1,7 +0,0 @@ -case class S1(n: Int) { } -case class S2(n: Int, p: Int) { } -class S3 { } -object S3 { - def foo() = "abc" - def bar[T](x: T): T = x -} diff --git a/tests/untried/pos/t175.scala b/tests/untried/pos/t175.scala deleted file mode 100644 index 4c0eb28ba..000000000 --- a/tests/untried/pos/t175.scala +++ /dev/null @@ -1,3 +0,0 @@ -abstract class C { - def this(x: Unit) = { this() } -} diff --git a/tests/untried/pos/t1751/A1_2.scala b/tests/untried/pos/t1751/A1_2.scala deleted file mode 100644 index 354d5eecd..000000000 --- a/tests/untried/pos/t1751/A1_2.scala +++ /dev/null @@ -1,2 +0,0 @@ -@SuiteClasses(Array(classOf[A2])) -class A1 diff --git a/tests/untried/pos/t1751/A2_1.scala b/tests/untried/pos/t1751/A2_1.scala deleted file mode 100644 index c768062e4..000000000 --- a/tests/untried/pos/t1751/A2_1.scala +++ /dev/null @@ -1,2 +0,0 @@ -@SuiteClasses(Array()) -class A2 diff --git a/tests/untried/pos/t1751/SuiteClasses.java b/tests/untried/pos/t1751/SuiteClasses.java deleted file mode 100644 index a415e4f57..000000000 --- a/tests/untried/pos/t1751/SuiteClasses.java +++ /dev/null @@ -1,3 +0,0 @@ -public @interface SuiteClasses { - public Class[] value(); -} diff --git a/tests/untried/pos/t1756.scala b/tests/untried/pos/t1756.scala deleted file mode 100755 index 1d067c3b0..000000000 --- a/tests/untried/pos/t1756.scala +++ /dev/null @@ -1,54 +0,0 @@ - -/** -This is a tricky issue which has to do with the fact that too much conflicting -type information is propagated into a single implicit search, where the intended -solution applies two implicit searches. - -Roughly, in x + x * y, the first x is first typed as Poly[A]. That -means the x * y is then typed as Poly[A]. Then the second x is typed -as Poly[A], then y is typed as Poly[Poly[A]]. The application x * y -fails, so the coef2poly implicit conversion is applied to x. That -means we look for an implicit conversion from type Poly[A] to type -?{val *(x$1: ?>: Poly[Poly[A]] <: Any): Poly[A]}. Note that the result -type Poly[A] is propagated into the implicit search. Poly[A] comes as -expected type from x+, because the lhs x is still typed as a Poly[A]. -This means that the argument of the implicit conversion is typechecked -with expected type A with Poly[A]. And no solution is found. - -To solve this, I added a fallback scheme similar to implicit arguments: -When an implicit view that adds a method matching given arguments and result -type fails, try again without the result type. -*/ -trait Ring[T <: Ring[T]] { - def +(that: T): T - def *(that: T): T -} - -class A extends Ring[A] { - def +(that: A) = new A - def *(that: A) = new A -} - -class Poly[C <: Ring[C]](val c: C) extends Ring[Poly[C]] { - def +(that: Poly[C]) = new Poly(this.c+that.c) - def *(that: Poly[C]) = new Poly(this.c*that.c) -} - -object Test extends App { - - implicit def coef2poly[C <: Ring[C]](c: C): Poly[C] = new Poly(c) - - val a = new A - val x = new Poly(new A) - - println(x+a) // works - println(a+x) // works - - val y = new Poly(new Poly(new A)) - - println(x+y*x) // works - println(x*y+x) // works - println(y*x+x) // works - - println(x+x*y) // failed before -} diff --git a/tests/untried/pos/t177.scala b/tests/untried/pos/t177.scala deleted file mode 100644 index 33b4de926..000000000 --- a/tests/untried/pos/t177.scala +++ /dev/null @@ -1,8 +0,0 @@ -class A { - def foo = { - object Y { - def bar = 1; - } - Y.bar - } -} diff --git a/tests/untried/pos/t1782/Ann.java b/tests/untried/pos/t1782/Ann.java deleted file mode 100644 index 0dcfbd2ed..000000000 --- a/tests/untried/pos/t1782/Ann.java +++ /dev/null @@ -1,3 +0,0 @@ -public @interface Ann { - public Days value(); -} diff --git a/tests/untried/pos/t1782/Days.java b/tests/untried/pos/t1782/Days.java deleted file mode 100644 index 203a87b1c..000000000 --- a/tests/untried/pos/t1782/Days.java +++ /dev/null @@ -1,3 +0,0 @@ -public enum Days { - Friday, Sunday -} diff --git a/tests/untried/pos/t1782/ImplementedBy.java b/tests/untried/pos/t1782/ImplementedBy.java deleted file mode 100644 index 6aa8b4fa9..000000000 --- a/tests/untried/pos/t1782/ImplementedBy.java +++ /dev/null @@ -1,3 +0,0 @@ -public @interface ImplementedBy { - public Class value(); -} diff --git a/tests/untried/pos/t1782/Test_1.scala b/tests/untried/pos/t1782/Test_1.scala deleted file mode 100644 index 6467a74c2..000000000 --- a/tests/untried/pos/t1782/Test_1.scala +++ /dev/null @@ -1,16 +0,0 @@ -@ImplementedBy(classOf[Provider]) -trait Service { - def someMethod() -} - -class Provider - extends Service -{ - // test enumeration java annotations - @Ann(Days.Friday) def someMethod() = () - - // #2103 - @scala.beans.BeanProperty - @Ann(value = Days.Sunday) - val t2103 = "test" -} diff --git a/tests/untried/pos/t1785.scala b/tests/untried/pos/t1785.scala deleted file mode 100644 index 0b1fafb27..000000000 --- a/tests/untried/pos/t1785.scala +++ /dev/null @@ -1,7 +0,0 @@ -class t1785 { - def apply[T](x: Int) = 1 -} - -object test { - (new t1785)[Int](1) -} diff --git a/tests/untried/pos/t1786-counter.scala b/tests/untried/pos/t1786-counter.scala deleted file mode 100644 index a2431343d..000000000 --- a/tests/untried/pos/t1786-counter.scala +++ /dev/null @@ -1,38 +0,0 @@ -trait ShapeLevel - -object Fail { - abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { - def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] - } - - abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] - - final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { - def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? - } - - trait ShapeLevel -} - -object Ok { - abstract class Shape[Level <: ShapeLevel, -Mixed_, Unpacked_, Packed_] - - abstract class ProductNodeShape[Level <: ShapeLevel, C, M <: C, U <: C, P <: C] extends Shape[Level, M, U, P] { - def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] - } - - final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { - def copy(shapes: Seq[Shape[_, _, _, _]]): Shape[Level, _, _, _] = ??? - } -} - -// This is why we reverted the fix for SI-1786 -- see SI-6169 for a potential alternative that could be extended to cover this. -// both objects type check on 2.10.3, but only Ok was accepted by 2.11 after the original fix to SI-1786. -// Fail results in: -/* -t1786-counter.scala:10: error: class TupleShape needs to be abstract, since method copy in class ProductNodeShape of type (shapes: Seq[Fail.Shape[_, _, _, _]])Fail.Shape[Level, _, _, _] is not defined -(Note that Seq[Fail.Shape[_, _, _, _]] does not match Seq[Fail.Shape[_ <: Fail.ShapeLevel, _, _, _]]: their type parameters differ) - final class TupleShape[Level <: ShapeLevel, M <: Product, U <: Product, P <: Product](val shapes: Shape[_, _, _, _]*) extends ProductNodeShape[Level, Product, M, U, P] { - ^ -one error found -*/ diff --git a/tests/untried/pos/t1786-cycle.scala b/tests/untried/pos/t1786-cycle.scala deleted file mode 100644 index 9de149fbc..000000000 --- a/tests/untried/pos/t1786-cycle.scala +++ /dev/null @@ -1,57 +0,0 @@ -trait GenTraversableLike[+A, +Repr] extends Any - -object O { - (null: Any) match { - case _: LongTraversableLike[_] => - } -} - -trait LongTraversable extends LongTraversableLike[LongTraversable] - -trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] - -/* -% scalac-hash v2.11.0-M8 test/files/pos/t1786-cycle.scala -[warn] v2.11.0-M8 failed, using closest available -test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike -trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenTraversableLike[Any, Repr] - ^ -one error found - -Okay again after SI-1786 was reverted. - - -|-- object O BYVALmode-EXPRmode (site: package ) -| |-- super EXPRmode-POLYmode-QUALmode (silent: in O) -| | |-- this EXPRmode (silent: in O) -| | | \-> O.type -| | \-> O.type -| |-- (null: Any) match { case (_: LongTraversableLike[(_ @ in O) -| | |-- (null: Any) BYVALmode-EXPRmode (site: value in O) -| | | |-- Any TYPEmode (site: value in O) -| | | | \-> Any -| | | |-- null : pt=Any EXPRmode (site: value in O) -| | | | \-> Null(null) -| | | \-> Any -| | |-- (_: LongTraversableLike[(_ @ )]) : pt=Any PATTERNmode (site: value in O) enrichment only -| | | |-- LongTraversableLike[(_ @ )] TYPEPATmode-TYPEmode (site: value in O) enrichment only -| | | | |-- <: LongTraversableLike[Repr] TYPEmode (site: type Repr in ) -| | | | | |-- LongTraversableLike[Repr] TYPEmode (site: type Repr in ) -| | | | | | |-- Repr NOmode (site: type Repr in ) -| | | | | | | \-> Repr -| | | | | | \-> LongTraversableLike[Repr] -| | | | | [adapt] <: LongTraversableLike[Repr] is now a TypeTree( <: LongTraversableLike[Repr]) -| | | | | \-> <: LongTraversableLike[Repr] -| | | | |-- (_ @ ) TYPEPATmode-TYPEmode (site: value in O) enrichment only -| | | | | \-> _ -| | | | |-- GenTraversableLike FUNmode-TYPEmode (site: trait LongTraversableLike) -| | | | | \-> GenTraversableLike -| | | | |-- GenTraversableLike[Any, Repr] TYPEmode (site: trait LongTraversableLike) -| | | | | |-- Any TYPEmode (site: trait LongTraversableLike) -| | | | | | \-> Any -| | | | | |-- Repr TYPEmode (site: trait LongTraversableLike) -| | | | | | \-> Repr -| | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving trait LongTraversableLike: while typing GenTraversableLike[Any, Repr] -test/files/pos/t1786-cycle.scala:11: error: illegal cyclic reference involving trait LongTraversableLike -trait LongTraversableLike[+Repr <: LongTraversableLike[Repr]] extends GenT -*/ diff --git a/tests/untried/pos/t1789.scala b/tests/untried/pos/t1789.scala deleted file mode 100644 index 1a37d48d0..000000000 --- a/tests/untried/pos/t1789.scala +++ /dev/null @@ -1,5 +0,0 @@ -object S { - try { } - catch { case _ => } - finally { while(true) { } } -} diff --git a/tests/untried/pos/t1798.scala b/tests/untried/pos/t1798.scala deleted file mode 100644 index 1624e3025..000000000 --- a/tests/untried/pos/t1798.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Foo { private def bar(): Int = 55 } -class Foo(x: Int) { def this() = this(Foo.bar()) } - -/* - * scalac28 a.scala -a.scala:2: error: method bar cannot be accessed in object Foo -class Foo(x: Int) { def this() = this(Foo.bar()) } - ^ -one error found -*/ diff --git a/tests/untried/pos/t1803.flags b/tests/untried/pos/t1803.flags deleted file mode 100644 index d1a824416..000000000 --- a/tests/untried/pos/t1803.flags +++ /dev/null @@ -1 +0,0 @@ --Yinfer-argument-types \ No newline at end of file diff --git a/tests/untried/pos/t1803.scala b/tests/untried/pos/t1803.scala deleted file mode 100644 index 42f4e784a..000000000 --- a/tests/untried/pos/t1803.scala +++ /dev/null @@ -1,2 +0,0 @@ -class A { def foo[A](a: A) = a } -class B extends A { override def foo[A](b) = b } diff --git a/tests/untried/pos/t183.scala b/tests/untried/pos/t183.scala deleted file mode 100644 index d7ed27f73..000000000 --- a/tests/untried/pos/t183.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test { - new Foo(0); - class Foo(x: Int); -} diff --git a/tests/untried/pos/t1832.scala b/tests/untried/pos/t1832.scala deleted file mode 100644 index 3a5280640..000000000 --- a/tests/untried/pos/t1832.scala +++ /dev/null @@ -1,8 +0,0 @@ -trait Cloning { - trait Foo - def fn(g: Any => Unit): Foo - - implicit def mkStar(i: Int): AnyRef{def *(a: Cloning.this.Foo): Cloning.this.Foo} = new { def *(a: Foo): Foo = null } - - val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } -} diff --git a/tests/untried/pos/t1836/J.java b/tests/untried/pos/t1836/J.java deleted file mode 100644 index a009a59e2..000000000 --- a/tests/untried/pos/t1836/J.java +++ /dev/null @@ -1 +0,0 @@ -public abstract class J { protected J(T id) { } } diff --git a/tests/untried/pos/t1836/S.scala b/tests/untried/pos/t1836/S.scala deleted file mode 100644 index 88ce1063e..000000000 --- a/tests/untried/pos/t1836/S.scala +++ /dev/null @@ -1 +0,0 @@ -class S extends J("") diff --git a/tests/untried/pos/t1840/J.java b/tests/untried/pos/t1840/J.java deleted file mode 100644 index fd98b6c4a..000000000 --- a/tests/untried/pos/t1840/J.java +++ /dev/null @@ -1,4 +0,0 @@ -package p; -class J { - J() {} -} diff --git a/tests/untried/pos/t1840/S.scala b/tests/untried/pos/t1840/S.scala deleted file mode 100644 index ff513d2c1..000000000 --- a/tests/untried/pos/t1840/S.scala +++ /dev/null @@ -1,2 +0,0 @@ -package p -class S { new J } diff --git a/tests/untried/pos/t1843.scala b/tests/untried/pos/t1843.scala deleted file mode 100644 index 8504bf342..000000000 --- a/tests/untried/pos/t1843.scala +++ /dev/null @@ -1,25 +0,0 @@ -/** -* Scala Compiler Will Crash On this File -* ... Or Will It? -* -*/ - -object Crash { - trait UpdateType[A] - case class StateUpdate[A](updateType : UpdateType[A], value : A) - case object IntegerUpdateType extends UpdateType[Integer] - - //However this method will cause a crash - def crash(updates: List[StateUpdate[_]]): Unit = { - updates match { - case Nil => - case u::us => - u match { - //Line below seems to be the crashing line - case StateUpdate(key, newValue) if (key == IntegerUpdateType) => - println("Requires a statement to induce the crash") - case _ => - } - } - } -} diff --git a/tests/untried/pos/t1858.scala b/tests/untried/pos/t1858.scala deleted file mode 100644 index c06e73e7e..000000000 --- a/tests/untried/pos/t1858.scala +++ /dev/null @@ -1,13 +0,0 @@ -import scala.collection.immutable.Stack - -object Test { - - def test = { - val s = new Stack[Int] - s.push(1) - s.push(1, 2) - s.push(1, 2, 3) - s.push(1, 2, 3, 4) - } - -} diff --git a/tests/untried/pos/t1896/D0.scala b/tests/untried/pos/t1896/D0.scala deleted file mode 100644 index 6b3150d96..000000000 --- a/tests/untried/pos/t1896/D0.scala +++ /dev/null @@ -1,11 +0,0 @@ -package p - -class X[T] - -trait A { - def m(s:X[_]): Unit = {} -} - -trait B extends A { - def f: Unit = { super.m(null) } -} diff --git a/tests/untried/pos/t1896/D1.scala b/tests/untried/pos/t1896/D1.scala deleted file mode 100644 index e1ab50679..000000000 --- a/tests/untried/pos/t1896/D1.scala +++ /dev/null @@ -1,2 +0,0 @@ -package p -class C extends B diff --git a/tests/untried/pos/t1937/NumberGenerator.java b/tests/untried/pos/t1937/NumberGenerator.java deleted file mode 100644 index 59d604733..000000000 --- a/tests/untried/pos/t1937/NumberGenerator.java +++ /dev/null @@ -1,7 +0,0 @@ -package br.com.caelum.caelumweb2.money; - -public class NumberGenerator { - public String generate() { - return null; - } -} diff --git a/tests/untried/pos/t1942/A_1.scala b/tests/untried/pos/t1942/A_1.scala deleted file mode 100644 index 4915b54a6..000000000 --- a/tests/untried/pos/t1942/A_1.scala +++ /dev/null @@ -1,11 +0,0 @@ -class A { - def foo(x: Int) = 0 - def foo(x: String) = 1 -} - -class ann(x: Int) extends annotation.StaticAnnotation - -class t { - val a = new A - @ann(a.foo(1)) def bar = 1 -} diff --git a/tests/untried/pos/t1942/Test_2.scala b/tests/untried/pos/t1942/Test_2.scala deleted file mode 100644 index 6c045bbce..000000000 --- a/tests/untried/pos/t1942/Test_2.scala +++ /dev/null @@ -1,3 +0,0 @@ -class Test { - println(new t) -} diff --git a/tests/untried/pos/t1957.scala b/tests/untried/pos/t1957.scala deleted file mode 100644 index 711ce17de..000000000 --- a/tests/untried/pos/t1957.scala +++ /dev/null @@ -1,38 +0,0 @@ -object Test { - abstract class Settings {} - - abstract class Grist - { self => - type settingsType <: Settings - type moduleType <: Module {type settingsType = self.settingsType} - val module: moduleType - } - - abstract class Tool - { self => - type settingsType <: Settings - type moduleType = Module { type settingsType = self.settingsType } - type gristType = Grist { type moduleType <: self.moduleType; type settingsType <: self.settingsType } - - def inputGrist: List[gristType] - } - - abstract class Module - { self => - type settingsType <: Settings - final type commonModuleType = Module {type settingsType = self.settingsType} - type selfType >: self.type <: commonModuleType - - // BTW: if we use the commented out type decls, the code compiles successfully - // type gristType = Grist {type settingsType <: self.settingsType; type moduleType <: commonModuleType } - - val tools: List[Tool {type settingsType = self.settingsType}] - - protected def f: List[commonModuleType] = - { - val inputGrists = tools.flatMap(_.inputGrist) // val inputGrists: List[gristType] = - inputGrists.map(_.module) - } - - } -} diff --git a/tests/untried/pos/t1974.scala b/tests/untried/pos/t1974.scala deleted file mode 100644 index 3f4d41e7f..000000000 --- a/tests/untried/pos/t1974.scala +++ /dev/null @@ -1,20 +0,0 @@ -object Broken { - private var map = Map[Class[_], String]() - - def addToMap(c : Class[_], s : String) = map += (c -> s) - def fetch(c : Class[_]) = map(c) -} - -object Works { - private var map = Map[Class[_], String]() - - def addToMap(c : Class[_], s : String) = map += ((c, s)) - def fetch(c : Class[_]) = map(c) -} - -object Works2 { - private var map = Map[Class[_], String]() - - def addToMap(c : Class[_], s : String) = map += ((c : Class[_]) -> s) - def fetch(c : Class[_]) = map(c) -} diff --git a/tests/untried/pos/t1987a.scala b/tests/untried/pos/t1987a.scala deleted file mode 100644 index ccab13371..000000000 --- a/tests/untried/pos/t1987a.scala +++ /dev/null @@ -1,8 +0,0 @@ -package object overloading { - def bar(f: (Int) => Unit): Unit = () - def bar(f: (Int, Int) => Unit): Unit = () -} - -class PackageObjectOverloadingTest { - overloading.bar( (i: Int) => () ) // doesn't compile. -} diff --git a/tests/untried/pos/t1987b/a.scala b/tests/untried/pos/t1987b/a.scala deleted file mode 100644 index ff27044b6..000000000 --- a/tests/untried/pos/t1987b/a.scala +++ /dev/null @@ -1,7 +0,0 @@ -package bug - -// goes with t1987b.scala -package object packageb { - def func(a: Int) = () - def func(a: String) = () -} diff --git a/tests/untried/pos/t1987b/b.scala b/tests/untried/pos/t1987b/b.scala deleted file mode 100644 index a469ca6ea..000000000 --- a/tests/untried/pos/t1987b/b.scala +++ /dev/null @@ -1,10 +0,0 @@ -// compile with t1987a.scala - -package bug.packageb -// Note that the overloading works if instead of being in the package we import it: -// replace the above line with import bug.packageb._ - -class Client { - val x = func(1) // doesn't compile: type mismatch; found: Int(1) required: String - val y = func("1") // compiles -} diff --git a/tests/untried/pos/t1996.scala b/tests/untried/pos/t1996.scala deleted file mode 100644 index 273012819..000000000 --- a/tests/untried/pos/t1996.scala +++ /dev/null @@ -1,19 +0,0 @@ -object forbug { - val l1 = List(List(ValDef(new A)), List(ValDef(new A))) - for ((e1s, e2s) <- l1.zip(l1); - (e1, e2) <- e1s.zip(e2s)) { - e1.a.doSome(20) -// () - } -} - - -class A { - def doSome(a: Int): this.type = { - println(a) - this - } -} - -case class ValDef(a: A) - -- cgit v1.2.3 From 093774e181e878308551226f6a0b990bf7de8077 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 6 May 2014 10:32:56 +0200 Subject: Fix of SI 2133 We now restrict wildcard imports to members that are accessible at the point of import. This is a fix of an open Scala ticket. --- src/dotty/tools/dotc/typer/Typer.scala | 3 ++- tests/pos/t2133.scala | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/pos/t2133.scala (limited to 'tests/pos') diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f4b52ce09..944b44510 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -70,6 +70,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit * (3) Change pattern Idents id (but not wildcards) to id @ _ */ def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = track("typedIdent") { + val refctx = ctx val name = tree.name /** Method is necessary because error messages need to bind to @@ -179,7 +180,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (imp.isWildcardImport) { val pre = imp.site if (!isDisabled(imp, pre) && !(imp.excluded contains name.toTermName)) { - val denot = pre.member(name) + val denot = pre.member(name).accessibleFrom(pre)(refctx) if (reallyExists(denot)) return pre.select(name, denot) } } diff --git a/tests/pos/t2133.scala b/tests/pos/t2133.scala new file mode 100644 index 000000000..02ef43c21 --- /dev/null +++ b/tests/pos/t2133.scala @@ -0,0 +1,18 @@ +trait Foo { + object bar { + private def fn() = 5 + } +} + +trait Foo2 { + object bip { + def fn() = 10 + } +} + +class Bob extends AnyRef with Foo with Foo2 { + import bip._ + import bar._ + + def go() = fn() +} -- cgit v1.2.3 From 2d3c79f7cf3e79b592c7e479d262e8d3f9b04959 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 6 May 2014 10:34:40 +0200 Subject: Tests pos 20xx 21xx --- .../not-representable/pos/t2066-2.10-compat.scala | 72 ++++++++++++++++++++++ tests/disabled/not-representable/pos/t2066.scala | 25 ++++++++ tests/pending/pos/t2060.scala | 44 +++++++++++++ tests/pos/t201.scala | 7 +++ tests/pos/t2018.scala | 15 +++++ tests/pos/t2023.scala | 16 +++++ tests/pos/t2038.scala | 5 ++ tests/pos/t2081.scala | 11 ++++ tests/pos/t2082.scala | 39 ++++++++++++ tests/pos/t2094.scala | 31 ++++++++++ tests/pos/t210.scala | 17 +++++ tests/pos/t211.scala | 8 +++ tests/pos/t2119.scala | 4 ++ tests/pos/t2127.scala | 5 ++ tests/pos/t2130-1.scala | 5 ++ tests/pos/t2130-2.scala | 17 +++++ tests/pos/t2168.scala | 4 ++ tests/pos/t2171.flags | 1 + tests/pos/t2171.scala | 7 +++ tests/pos/t2179.scala | 3 + tests/pos/t2183.scala | 5 ++ tests/pos/t2187-2.scala | 7 +++ tests/pos/t2187.scala | 7 +++ tests/pos/t2194.scala | 8 +++ tests/untried/pos/t201.scala | 7 --- tests/untried/pos/t2018.scala | 15 ----- tests/untried/pos/t2023.scala | 16 ----- tests/untried/pos/t2038.scala | 5 -- tests/untried/pos/t2060.scala | 44 ------------- tests/untried/pos/t2066-2.10-compat.flags | 1 - tests/untried/pos/t2066-2.10-compat.scala | 71 --------------------- tests/untried/pos/t2066.scala | 25 -------- tests/untried/pos/t2081.scala | 11 ---- tests/untried/pos/t2082.scala | 39 ------------ tests/untried/pos/t2094.scala | 31 ---------- tests/untried/pos/t210.scala | 17 ----- tests/untried/pos/t211.scala | 8 --- tests/untried/pos/t2119.scala | 4 -- tests/untried/pos/t2127.scala | 5 -- tests/untried/pos/t2130-1.scala | 5 -- tests/untried/pos/t2130-2.scala | 17 ----- tests/untried/pos/t2133.scala | 18 ------ tests/untried/pos/t2168.scala | 4 -- tests/untried/pos/t2171.flags | 1 - tests/untried/pos/t2171.scala | 7 --- tests/untried/pos/t2179.scala | 3 - tests/untried/pos/t2183.scala | 5 -- tests/untried/pos/t2187-2.scala | 7 --- tests/untried/pos/t2187.scala | 7 --- tests/untried/pos/t2194.scala | 8 --- 50 files changed, 363 insertions(+), 381 deletions(-) create mode 100644 tests/disabled/not-representable/pos/t2066-2.10-compat.scala create mode 100644 tests/disabled/not-representable/pos/t2066.scala create mode 100755 tests/pending/pos/t2060.scala create mode 100644 tests/pos/t201.scala create mode 100644 tests/pos/t2018.scala create mode 100644 tests/pos/t2023.scala create mode 100644 tests/pos/t2038.scala create mode 100644 tests/pos/t2081.scala create mode 100755 tests/pos/t2082.scala create mode 100644 tests/pos/t2094.scala create mode 100644 tests/pos/t210.scala create mode 100644 tests/pos/t211.scala create mode 100644 tests/pos/t2119.scala create mode 100644 tests/pos/t2127.scala create mode 100644 tests/pos/t2130-1.scala create mode 100644 tests/pos/t2130-2.scala create mode 100644 tests/pos/t2168.scala create mode 100644 tests/pos/t2171.flags create mode 100644 tests/pos/t2171.scala create mode 100755 tests/pos/t2179.scala create mode 100644 tests/pos/t2183.scala create mode 100644 tests/pos/t2187-2.scala create mode 100644 tests/pos/t2187.scala create mode 100644 tests/pos/t2194.scala delete mode 100644 tests/untried/pos/t201.scala delete mode 100644 tests/untried/pos/t2018.scala delete mode 100644 tests/untried/pos/t2023.scala delete mode 100644 tests/untried/pos/t2038.scala delete mode 100755 tests/untried/pos/t2060.scala delete mode 100644 tests/untried/pos/t2066-2.10-compat.flags delete mode 100644 tests/untried/pos/t2066-2.10-compat.scala delete mode 100644 tests/untried/pos/t2066.scala delete mode 100644 tests/untried/pos/t2081.scala delete mode 100755 tests/untried/pos/t2082.scala delete mode 100644 tests/untried/pos/t2094.scala delete mode 100644 tests/untried/pos/t210.scala delete mode 100644 tests/untried/pos/t211.scala delete mode 100644 tests/untried/pos/t2119.scala delete mode 100644 tests/untried/pos/t2127.scala delete mode 100644 tests/untried/pos/t2130-1.scala delete mode 100644 tests/untried/pos/t2130-2.scala delete mode 100644 tests/untried/pos/t2133.scala delete mode 100644 tests/untried/pos/t2168.scala delete mode 100644 tests/untried/pos/t2171.flags delete mode 100644 tests/untried/pos/t2171.scala delete mode 100755 tests/untried/pos/t2179.scala delete mode 100644 tests/untried/pos/t2183.scala delete mode 100644 tests/untried/pos/t2187-2.scala delete mode 100644 tests/untried/pos/t2187.scala delete mode 100644 tests/untried/pos/t2194.scala (limited to 'tests/pos') diff --git a/tests/disabled/not-representable/pos/t2066-2.10-compat.scala b/tests/disabled/not-representable/pos/t2066-2.10-compat.scala new file mode 100644 index 000000000..9cbf0092a --- /dev/null +++ b/tests/disabled/not-representable/pos/t2066-2.10-compat.scala @@ -0,0 +1,72 @@ +import language._ +trait A1 { + def f[T[_]] = () +} + +trait B1 extends A1 { + override def f[T[+_]] = () +} + +trait C1 extends A1 { + override def f[T[-_]] = () +} + + +trait A2 { + def f[T[+_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () // okay +} + +trait C2 extends A2 { + override def f[T[-_]] = () +} + + +trait A3 { + def f[T[-_]] = () +} + +trait B3 extends A3 { + override def f[T[_]] = () // okay +} + +// These nested higher-kinded types are not parsable in Dotty= +trait C3 extends A3 { + override def f[T[-_]] = () +} + + +trait A4 { + def f[T[X[+_]]] = () +} + +trait B4 extends A4 { + override def f[T[X[_]]] = () +} + +trait A5 { + def f[T[X[-_]]] = () +} + +trait B5 extends A5 { + override def f[T[X[_]]] = () +} + + + +trait A6 { + def f[T[X[_]]] = () +} + +trait B6 extends A6 { + override def f[T[X[+_]]] = () // okay +} +trait C6 extends A6 { + override def f[T[X[_]]] = () // okay +} +trait D6 extends A6 { + override def f[T[X[-_]]] = () +} diff --git a/tests/disabled/not-representable/pos/t2066.scala b/tests/disabled/not-representable/pos/t2066.scala new file mode 100644 index 000000000..30cb99d45 --- /dev/null +++ b/tests/disabled/not-representable/pos/t2066.scala @@ -0,0 +1,25 @@ +trait A1 { + def f[T[+_]] = () +} + +trait B1 extends A1 { + override def f[T[_]] = () +} + + +trait A2 { + def f[T[-_]] = () +} + +trait B2 extends A2 { + override def f[T[_]] = () +} + + +trait A3 { + def f[T[X[_]]] = () +} + +trait B3 extends A3 { + override def f[T[X[+_]]] = () +} diff --git a/tests/pending/pos/t2060.scala b/tests/pending/pos/t2060.scala new file mode 100755 index 000000000..0b9079062 --- /dev/null +++ b/tests/pending/pos/t2060.scala @@ -0,0 +1,44 @@ +/* The problem here is that we cannot insert an implicit to + * add a polymorphic method which is then instantiated to the + * right type. When searching for the implicit in the `fails to compile + * line': + * + * val failure = 1.0 + new Op[Int] + * + * we reduce the problem to finding a function from Double to + * {+: _ >: Op[Int] <: Any}, that is, a method which takes + * an argument which is an Op[Int] or a supertype thereof. + * Class Rich is not a subtype of this structural record, because + * polymorphic method instantiation is not contained in subtyping. + * That is: The method type [I](op : Op[I]): Op[I] is not a subtype + * of (Op[Int]): Op[Int]. + * At present it is unclear whether this problem can be solved. + */ +object Test { + class Op[I]; + class IntOp extends Op[Int]; + + class Rich(x : Double) { + def + (op : IntOp): IntOp = op; + def + [I](op : Op[I]): Op[I] = op; + def plus [I](op : Op[I]): Op[I] = op; + } + + implicit def iToRich(x : Double): Test.Rich = + new Rich(x); + + // fails to compile + val x = 1.0 + new Op[Int] + + // works as expected -- + // problem isn't in adding new "+" + val a = 1.0 + new IntOp; + + // works as expected -- + // problem isn't in binding type variable I + val b = 1.0 plus new Op[Int]; + + // works as expected -- + // problem isn't in using Rich.+[I](op : Op[I]) + val c = iToRich(1.0) + new Op[Int]; +} diff --git a/tests/pos/t201.scala b/tests/pos/t201.scala new file mode 100644 index 000000000..b0c6b8da4 --- /dev/null +++ b/tests/pos/t201.scala @@ -0,0 +1,7 @@ +class C[a] { def f: a = f; } +class D[b] { class E extends C[b]; } +object Test { + val d = new D[Int]; + def e = new d.E; + e.f; +} diff --git a/tests/pos/t2018.scala b/tests/pos/t2018.scala new file mode 100644 index 000000000..198b4be42 --- /dev/null +++ b/tests/pos/t2018.scala @@ -0,0 +1,15 @@ +class A { + val b = new B + + def getChildren = List(new A).iterator + + class B { + private def check = true + + private def getAncestor(p: A): A = { + val c = (p.getChildren.find(_.b.check)) match {case Some(d) => d case None => p} + + if (c == p) p else c.b.getAncestor(c) + } + } +} diff --git a/tests/pos/t2023.scala b/tests/pos/t2023.scala new file mode 100644 index 000000000..21c6fc96a --- /dev/null +++ b/tests/pos/t2023.scala @@ -0,0 +1,16 @@ +trait C[A] + +object C { + implicit def ipl[A](implicit from: A => Ordered[A]): C[A] = null +} + +object P { + def foo[A](i: A, j: A)(implicit c: C[A]): Unit = () +} + +class ImplicitChainTest { + def testTrivial: Unit = { + P.foo('0', '9') + P.foo('0', '9') + } +} diff --git a/tests/pos/t2038.scala b/tests/pos/t2038.scala new file mode 100644 index 000000000..8c8ca44da --- /dev/null +++ b/tests/pos/t2038.scala @@ -0,0 +1,5 @@ +class Test { + List(Some(classOf[java.lang.Integer]), Some(classOf[Int])).map { + case Some(f: Class[_]) => f.cast(???) + } +} diff --git a/tests/pos/t2081.scala b/tests/pos/t2081.scala new file mode 100644 index 000000000..395134f71 --- /dev/null +++ b/tests/pos/t2081.scala @@ -0,0 +1,11 @@ +object ScalaForRubyists { + class RichInt(n: Int) { + def days = 1000*60*60*24*n + } + + implicit def RichInt(n: Int): RichInt = new RichInt(n) + + val x = 10.days + // a couple parser corner cases I wanted not to break + val y = 5.0e0 + 5e7 +} diff --git a/tests/pos/t2082.scala b/tests/pos/t2082.scala new file mode 100755 index 000000000..a7ee3789b --- /dev/null +++ b/tests/pos/t2082.scala @@ -0,0 +1,39 @@ + +trait Mapper[T <: Mapper[T]] + +trait KeyedMapper[KeyType, T <: KeyedMapper[KeyType, T]] extends Mapper[T] + + +trait KeyedMetaMapper[KeyType, T <: KeyedMapper[KeyType, T]] + +trait MappedForeignKey[KeyType, Owner <: Mapper[Owner], Other <: KeyedMapper[KeyType, Other]] + +trait IdPK + +class TestSubject extends KeyedMapper[Long, TestSubject] with IdPK + +class TestRun extends KeyedMapper[Long, TestRun] with IdPK { + object testSubject extends MappedForeignKey[Long, TestRun, TestSubject] +} + +object TestRun extends TestRun with KeyedMetaMapper[Long, TestRun] + +class MetaTestSubject extends TestSubject with KeyedMetaMapper[Long, TestSubject] +object TestSubject extends MetaTestSubject + +object Main { + + def oneToOneJoin[PType <: KeyedMapper[Long, PType] with IdPK, + CType <: KeyedMapper[Long, CType] with IdPK, + CMetaType <: CType with KeyedMetaMapper[Long, CType], + FKType <: MappedForeignKey[Long, PType, CType]] + (parents: List[PType], metaMapper: CMetaType, keyGetter: (PType) => FKType ): + Map[Long, CType] = Map.empty + + def callIt: Unit = { + oneToOneJoin[TestRun, TestSubject, MetaTestSubject, + MappedForeignKey[Long, TestRun, TestSubject]]( + List(), TestSubject, (tr: TestRun) => tr.testSubject) + } + +} diff --git a/tests/pos/t2094.scala b/tests/pos/t2094.scala new file mode 100644 index 000000000..6b6c4f077 --- /dev/null +++ b/tests/pos/t2094.scala @@ -0,0 +1,31 @@ +object Test extends App { + // compiles: + Map[Int, Value]( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // does not compile: + Map( + 0 -> KnownType(classOf[Object]), + 1 -> UnknownValue()) + + // Experiment.scala:10: error: type mismatch; + // found : (Int, KnownType) + // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 + // 0 -> KnownType(classOf[Object]), + // ^ + // one error found +} +sealed trait Value { + def getType: Option[Class[_]] +} + +case class UnknownValue() extends Value { + def getType = None + // compiles if changed to: + // def getType: Option[Class[_]] = None +} + +case class KnownType(typ: Class[_]) extends Value { + def getType = Some(typ) +} diff --git a/tests/pos/t210.scala b/tests/pos/t210.scala new file mode 100644 index 000000000..f0b907aa5 --- /dev/null +++ b/tests/pos/t210.scala @@ -0,0 +1,17 @@ +trait Lang1 { + trait Exp; + trait Visitor { def f(left: Exp): Unit } + class Eval1 extends Visitor { self: Visitor => + def f(left: Exp) = () + } +} + +trait Lang2 extends Lang1 { + class Eval2 extends Eval1 { self: Visitor => } +} +/* +object Main with App { + val lang2 = new Lang2 {} + val eval = new lang2.Eval2 +} +*/ diff --git a/tests/pos/t211.scala b/tests/pos/t211.scala new file mode 100644 index 000000000..d51c9706d --- /dev/null +++ b/tests/pos/t211.scala @@ -0,0 +1,8 @@ +trait A; +trait B; +class Foo extends A with B { self: A with B => } +object Test extends App { + new Foo(); + Console.println("t211 completed"); +} + diff --git a/tests/pos/t2119.scala b/tests/pos/t2119.scala new file mode 100644 index 000000000..b9cb4d9c6 --- /dev/null +++ b/tests/pos/t2119.scala @@ -0,0 +1,4 @@ +class A { + val orig = new java.util.ArrayList[String] + val copy = new java.util.ArrayList(orig) +} diff --git a/tests/pos/t2127.scala b/tests/pos/t2127.scala new file mode 100644 index 000000000..88cc9e708 --- /dev/null +++ b/tests/pos/t2127.scala @@ -0,0 +1,5 @@ +class Foo private (val value : Int) + +abstract class Bar(val ctor : (Int) => Foo) + +object Foo extends Bar(new Foo(_)) //<--- ILLEGAL ACCESS diff --git a/tests/pos/t2130-1.scala b/tests/pos/t2130-1.scala new file mode 100644 index 000000000..8dd61c4d3 --- /dev/null +++ b/tests/pos/t2130-1.scala @@ -0,0 +1,5 @@ +package foo + +package object bar { + case class Bippy(x: Int) { } +} diff --git a/tests/pos/t2130-2.scala b/tests/pos/t2130-2.scala new file mode 100644 index 000000000..1d0b33c3e --- /dev/null +++ b/tests/pos/t2130-2.scala @@ -0,0 +1,17 @@ +package foo + +package object bar { + class Bippy(x: Int) { + class Ding + object Ding + case class Dong(x: Float) + } + object Bippy { + class Dingus + object Dingus + case class Dongus(x: Float) + + def apply(xs: Int*) = new Bippy(xs.sum) + def apply() = new Bippy(5) + } +} diff --git a/tests/pos/t2168.scala b/tests/pos/t2168.scala new file mode 100644 index 000000000..21afb239a --- /dev/null +++ b/tests/pos/t2168.scala @@ -0,0 +1,4 @@ +object Test extends App { + def foo1(x: AnyRef) = x match { case x: Function0[_] => x() } + def foo2(x: AnyRef) = x match { case x: Function0[Any] => x() } +} diff --git a/tests/pos/t2171.flags b/tests/pos/t2171.flags new file mode 100644 index 000000000..eb4d19bcb --- /dev/null +++ b/tests/pos/t2171.flags @@ -0,0 +1 @@ +-optimise \ No newline at end of file diff --git a/tests/pos/t2171.scala b/tests/pos/t2171.scala new file mode 100644 index 000000000..6c754c76a --- /dev/null +++ b/tests/pos/t2171.scala @@ -0,0 +1,7 @@ +final object test { + def logIgnoredException(msg: => String) = + try 0 catch { case ex => println(msg) } + + def main (args: Array[String]): Unit = + while (true) logIgnoredException ("...") +} diff --git a/tests/pos/t2179.scala b/tests/pos/t2179.scala new file mode 100755 index 000000000..89e22b6e2 --- /dev/null +++ b/tests/pos/t2179.scala @@ -0,0 +1,3 @@ +object Test { + (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) +} diff --git a/tests/pos/t2183.scala b/tests/pos/t2183.scala new file mode 100644 index 000000000..1243568b6 --- /dev/null +++ b/tests/pos/t2183.scala @@ -0,0 +1,5 @@ +import scala.collection.mutable._ + +object Test { + val m = new HashSet[String] with SynchronizedSet[String] +} diff --git a/tests/pos/t2187-2.scala b/tests/pos/t2187-2.scala new file mode 100644 index 000000000..506cc496f --- /dev/null +++ b/tests/pos/t2187-2.scala @@ -0,0 +1,7 @@ +class Test { + def test[A](list: List[A]) = list match { + case Seq(x, y) => "xy" + case Seq(x) => "x" + case _ => "something else" + } +} diff --git a/tests/pos/t2187.scala b/tests/pos/t2187.scala new file mode 100644 index 000000000..8a3353154 --- /dev/null +++ b/tests/pos/t2187.scala @@ -0,0 +1,7 @@ +// bug #2187 +object Test extends App { + def foo(xs:List[String]) = xs match { + case Seq(x) => x + case Seq(x,y) => "" + } +} diff --git a/tests/pos/t2194.scala b/tests/pos/t2194.scala new file mode 100644 index 000000000..e87be509d --- /dev/null +++ b/tests/pos/t2194.scala @@ -0,0 +1,8 @@ +// tricky to do differently? +class C + +object Test { + def f = { object o extends C; o} + val y: C = f + val x = f +} diff --git a/tests/untried/pos/t201.scala b/tests/untried/pos/t201.scala deleted file mode 100644 index b0c6b8da4..000000000 --- a/tests/untried/pos/t201.scala +++ /dev/null @@ -1,7 +0,0 @@ -class C[a] { def f: a = f; } -class D[b] { class E extends C[b]; } -object Test { - val d = new D[Int]; - def e = new d.E; - e.f; -} diff --git a/tests/untried/pos/t2018.scala b/tests/untried/pos/t2018.scala deleted file mode 100644 index 198b4be42..000000000 --- a/tests/untried/pos/t2018.scala +++ /dev/null @@ -1,15 +0,0 @@ -class A { - val b = new B - - def getChildren = List(new A).iterator - - class B { - private def check = true - - private def getAncestor(p: A): A = { - val c = (p.getChildren.find(_.b.check)) match {case Some(d) => d case None => p} - - if (c == p) p else c.b.getAncestor(c) - } - } -} diff --git a/tests/untried/pos/t2023.scala b/tests/untried/pos/t2023.scala deleted file mode 100644 index 21c6fc96a..000000000 --- a/tests/untried/pos/t2023.scala +++ /dev/null @@ -1,16 +0,0 @@ -trait C[A] - -object C { - implicit def ipl[A](implicit from: A => Ordered[A]): C[A] = null -} - -object P { - def foo[A](i: A, j: A)(implicit c: C[A]): Unit = () -} - -class ImplicitChainTest { - def testTrivial: Unit = { - P.foo('0', '9') - P.foo('0', '9') - } -} diff --git a/tests/untried/pos/t2038.scala b/tests/untried/pos/t2038.scala deleted file mode 100644 index 8c8ca44da..000000000 --- a/tests/untried/pos/t2038.scala +++ /dev/null @@ -1,5 +0,0 @@ -class Test { - List(Some(classOf[java.lang.Integer]), Some(classOf[Int])).map { - case Some(f: Class[_]) => f.cast(???) - } -} diff --git a/tests/untried/pos/t2060.scala b/tests/untried/pos/t2060.scala deleted file mode 100755 index 0b9079062..000000000 --- a/tests/untried/pos/t2060.scala +++ /dev/null @@ -1,44 +0,0 @@ -/* The problem here is that we cannot insert an implicit to - * add a polymorphic method which is then instantiated to the - * right type. When searching for the implicit in the `fails to compile - * line': - * - * val failure = 1.0 + new Op[Int] - * - * we reduce the problem to finding a function from Double to - * {+: _ >: Op[Int] <: Any}, that is, a method which takes - * an argument which is an Op[Int] or a supertype thereof. - * Class Rich is not a subtype of this structural record, because - * polymorphic method instantiation is not contained in subtyping. - * That is: The method type [I](op : Op[I]): Op[I] is not a subtype - * of (Op[Int]): Op[Int]. - * At present it is unclear whether this problem can be solved. - */ -object Test { - class Op[I]; - class IntOp extends Op[Int]; - - class Rich(x : Double) { - def + (op : IntOp): IntOp = op; - def + [I](op : Op[I]): Op[I] = op; - def plus [I](op : Op[I]): Op[I] = op; - } - - implicit def iToRich(x : Double): Test.Rich = - new Rich(x); - - // fails to compile - val x = 1.0 + new Op[Int] - - // works as expected -- - // problem isn't in adding new "+" - val a = 1.0 + new IntOp; - - // works as expected -- - // problem isn't in binding type variable I - val b = 1.0 plus new Op[Int]; - - // works as expected -- - // problem isn't in using Rich.+[I](op : Op[I]) - val c = iToRich(1.0) + new Op[Int]; -} diff --git a/tests/untried/pos/t2066-2.10-compat.flags b/tests/untried/pos/t2066-2.10-compat.flags deleted file mode 100644 index 94c805674..000000000 --- a/tests/untried/pos/t2066-2.10-compat.flags +++ /dev/null @@ -1 +0,0 @@ --Xsource:2.10 diff --git a/tests/untried/pos/t2066-2.10-compat.scala b/tests/untried/pos/t2066-2.10-compat.scala deleted file mode 100644 index fb8103e4a..000000000 --- a/tests/untried/pos/t2066-2.10-compat.scala +++ /dev/null @@ -1,71 +0,0 @@ -import language._ -trait A1 { - def f[T[_]] = () -} - -trait B1 extends A1 { - override def f[T[+_]] = () -} - -trait C1 extends A1 { - override def f[T[-_]] = () -} - - -trait A2 { - def f[T[+_]] = () -} - -trait B2 extends A2 { - override def f[T[_]] = () // okay -} - -trait C2 extends A2 { - override def f[T[-_]] = () -} - - -trait A3 { - def f[T[-_]] = () -} - -trait B3 extends A3 { - override def f[T[_]] = () // okay -} - -trait C3 extends A3 { - override def f[T[-_]] = () -} - - -trait A4 { - def f[T[X[+_]]] = () -} - -trait B4 extends A4 { - override def f[T[X[_]]] = () -} - -trait A5 { - def f[T[X[-_]]] = () -} - -trait B5 extends A5 { - override def f[T[X[_]]] = () -} - - - -trait A6 { - def f[T[X[_]]] = () -} - -trait B6 extends A6 { - override def f[T[X[+_]]] = () // okay -} -trait C6 extends A6 { - override def f[T[X[_]]] = () // okay -} -trait D6 extends A6 { - override def f[T[X[-_]]] = () -} diff --git a/tests/untried/pos/t2066.scala b/tests/untried/pos/t2066.scala deleted file mode 100644 index 30cb99d45..000000000 --- a/tests/untried/pos/t2066.scala +++ /dev/null @@ -1,25 +0,0 @@ -trait A1 { - def f[T[+_]] = () -} - -trait B1 extends A1 { - override def f[T[_]] = () -} - - -trait A2 { - def f[T[-_]] = () -} - -trait B2 extends A2 { - override def f[T[_]] = () -} - - -trait A3 { - def f[T[X[_]]] = () -} - -trait B3 extends A3 { - override def f[T[X[+_]]] = () -} diff --git a/tests/untried/pos/t2081.scala b/tests/untried/pos/t2081.scala deleted file mode 100644 index 395134f71..000000000 --- a/tests/untried/pos/t2081.scala +++ /dev/null @@ -1,11 +0,0 @@ -object ScalaForRubyists { - class RichInt(n: Int) { - def days = 1000*60*60*24*n - } - - implicit def RichInt(n: Int): RichInt = new RichInt(n) - - val x = 10.days - // a couple parser corner cases I wanted not to break - val y = 5.0e0 + 5e7 -} diff --git a/tests/untried/pos/t2082.scala b/tests/untried/pos/t2082.scala deleted file mode 100755 index a7ee3789b..000000000 --- a/tests/untried/pos/t2082.scala +++ /dev/null @@ -1,39 +0,0 @@ - -trait Mapper[T <: Mapper[T]] - -trait KeyedMapper[KeyType, T <: KeyedMapper[KeyType, T]] extends Mapper[T] - - -trait KeyedMetaMapper[KeyType, T <: KeyedMapper[KeyType, T]] - -trait MappedForeignKey[KeyType, Owner <: Mapper[Owner], Other <: KeyedMapper[KeyType, Other]] - -trait IdPK - -class TestSubject extends KeyedMapper[Long, TestSubject] with IdPK - -class TestRun extends KeyedMapper[Long, TestRun] with IdPK { - object testSubject extends MappedForeignKey[Long, TestRun, TestSubject] -} - -object TestRun extends TestRun with KeyedMetaMapper[Long, TestRun] - -class MetaTestSubject extends TestSubject with KeyedMetaMapper[Long, TestSubject] -object TestSubject extends MetaTestSubject - -object Main { - - def oneToOneJoin[PType <: KeyedMapper[Long, PType] with IdPK, - CType <: KeyedMapper[Long, CType] with IdPK, - CMetaType <: CType with KeyedMetaMapper[Long, CType], - FKType <: MappedForeignKey[Long, PType, CType]] - (parents: List[PType], metaMapper: CMetaType, keyGetter: (PType) => FKType ): - Map[Long, CType] = Map.empty - - def callIt: Unit = { - oneToOneJoin[TestRun, TestSubject, MetaTestSubject, - MappedForeignKey[Long, TestRun, TestSubject]]( - List(), TestSubject, (tr: TestRun) => tr.testSubject) - } - -} diff --git a/tests/untried/pos/t2094.scala b/tests/untried/pos/t2094.scala deleted file mode 100644 index 6b6c4f077..000000000 --- a/tests/untried/pos/t2094.scala +++ /dev/null @@ -1,31 +0,0 @@ -object Test extends App { - // compiles: - Map[Int, Value]( - 0 -> KnownType(classOf[Object]), - 1 -> UnknownValue()) - - // does not compile: - Map( - 0 -> KnownType(classOf[Object]), - 1 -> UnknownValue()) - - // Experiment.scala:10: error: type mismatch; - // found : (Int, KnownType) - // required: (Int, Product with Value{def getType: Option[java.lang.Class[_$$2]]}) where type _$$2 - // 0 -> KnownType(classOf[Object]), - // ^ - // one error found -} -sealed trait Value { - def getType: Option[Class[_]] -} - -case class UnknownValue() extends Value { - def getType = None - // compiles if changed to: - // def getType: Option[Class[_]] = None -} - -case class KnownType(typ: Class[_]) extends Value { - def getType = Some(typ) -} diff --git a/tests/untried/pos/t210.scala b/tests/untried/pos/t210.scala deleted file mode 100644 index f0b907aa5..000000000 --- a/tests/untried/pos/t210.scala +++ /dev/null @@ -1,17 +0,0 @@ -trait Lang1 { - trait Exp; - trait Visitor { def f(left: Exp): Unit } - class Eval1 extends Visitor { self: Visitor => - def f(left: Exp) = () - } -} - -trait Lang2 extends Lang1 { - class Eval2 extends Eval1 { self: Visitor => } -} -/* -object Main with App { - val lang2 = new Lang2 {} - val eval = new lang2.Eval2 -} -*/ diff --git a/tests/untried/pos/t211.scala b/tests/untried/pos/t211.scala deleted file mode 100644 index d51c9706d..000000000 --- a/tests/untried/pos/t211.scala +++ /dev/null @@ -1,8 +0,0 @@ -trait A; -trait B; -class Foo extends A with B { self: A with B => } -object Test extends App { - new Foo(); - Console.println("t211 completed"); -} - diff --git a/tests/untried/pos/t2119.scala b/tests/untried/pos/t2119.scala deleted file mode 100644 index b9cb4d9c6..000000000 --- a/tests/untried/pos/t2119.scala +++ /dev/null @@ -1,4 +0,0 @@ -class A { - val orig = new java.util.ArrayList[String] - val copy = new java.util.ArrayList(orig) -} diff --git a/tests/untried/pos/t2127.scala b/tests/untried/pos/t2127.scala deleted file mode 100644 index 88cc9e708..000000000 --- a/tests/untried/pos/t2127.scala +++ /dev/null @@ -1,5 +0,0 @@ -class Foo private (val value : Int) - -abstract class Bar(val ctor : (Int) => Foo) - -object Foo extends Bar(new Foo(_)) //<--- ILLEGAL ACCESS diff --git a/tests/untried/pos/t2130-1.scala b/tests/untried/pos/t2130-1.scala deleted file mode 100644 index 8dd61c4d3..000000000 --- a/tests/untried/pos/t2130-1.scala +++ /dev/null @@ -1,5 +0,0 @@ -package foo - -package object bar { - case class Bippy(x: Int) { } -} diff --git a/tests/untried/pos/t2130-2.scala b/tests/untried/pos/t2130-2.scala deleted file mode 100644 index 1d0b33c3e..000000000 --- a/tests/untried/pos/t2130-2.scala +++ /dev/null @@ -1,17 +0,0 @@ -package foo - -package object bar { - class Bippy(x: Int) { - class Ding - object Ding - case class Dong(x: Float) - } - object Bippy { - class Dingus - object Dingus - case class Dongus(x: Float) - - def apply(xs: Int*) = new Bippy(xs.sum) - def apply() = new Bippy(5) - } -} diff --git a/tests/untried/pos/t2133.scala b/tests/untried/pos/t2133.scala deleted file mode 100644 index c74d0a4bb..000000000 --- a/tests/untried/pos/t2133.scala +++ /dev/null @@ -1,18 +0,0 @@ -trait Foo { - object bar { - private[this] def fn() = 5 - } -} - -trait Foo2 { - object bip { - def fn() = 10 - } -} - -class Bob extends AnyRef with Foo with Foo2 { - import bip._ - import bar._ - - def go() = fn() -} diff --git a/tests/untried/pos/t2168.scala b/tests/untried/pos/t2168.scala deleted file mode 100644 index 21afb239a..000000000 --- a/tests/untried/pos/t2168.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test extends App { - def foo1(x: AnyRef) = x match { case x: Function0[_] => x() } - def foo2(x: AnyRef) = x match { case x: Function0[Any] => x() } -} diff --git a/tests/untried/pos/t2171.flags b/tests/untried/pos/t2171.flags deleted file mode 100644 index eb4d19bcb..000000000 --- a/tests/untried/pos/t2171.flags +++ /dev/null @@ -1 +0,0 @@ --optimise \ No newline at end of file diff --git a/tests/untried/pos/t2171.scala b/tests/untried/pos/t2171.scala deleted file mode 100644 index 6c754c76a..000000000 --- a/tests/untried/pos/t2171.scala +++ /dev/null @@ -1,7 +0,0 @@ -final object test { - def logIgnoredException(msg: => String) = - try 0 catch { case ex => println(msg) } - - def main (args: Array[String]): Unit = - while (true) logIgnoredException ("...") -} diff --git a/tests/untried/pos/t2179.scala b/tests/untried/pos/t2179.scala deleted file mode 100755 index 89e22b6e2..000000000 --- a/tests/untried/pos/t2179.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - (Nil:List[List[Double]]).reduceLeft((_: Any, _: Any) => Nil.indices.map(_ => 0d)) -} diff --git a/tests/untried/pos/t2183.scala b/tests/untried/pos/t2183.scala deleted file mode 100644 index 1243568b6..000000000 --- a/tests/untried/pos/t2183.scala +++ /dev/null @@ -1,5 +0,0 @@ -import scala.collection.mutable._ - -object Test { - val m = new HashSet[String] with SynchronizedSet[String] -} diff --git a/tests/untried/pos/t2187-2.scala b/tests/untried/pos/t2187-2.scala deleted file mode 100644 index 506cc496f..000000000 --- a/tests/untried/pos/t2187-2.scala +++ /dev/null @@ -1,7 +0,0 @@ -class Test { - def test[A](list: List[A]) = list match { - case Seq(x, y) => "xy" - case Seq(x) => "x" - case _ => "something else" - } -} diff --git a/tests/untried/pos/t2187.scala b/tests/untried/pos/t2187.scala deleted file mode 100644 index 8a3353154..000000000 --- a/tests/untried/pos/t2187.scala +++ /dev/null @@ -1,7 +0,0 @@ -// bug #2187 -object Test extends App { - def foo(xs:List[String]) = xs match { - case Seq(x) => x - case Seq(x,y) => "" - } -} diff --git a/tests/untried/pos/t2194.scala b/tests/untried/pos/t2194.scala deleted file mode 100644 index e87be509d..000000000 --- a/tests/untried/pos/t2194.scala +++ /dev/null @@ -1,8 +0,0 @@ -// tricky to do differently? -class C - -object Test { - def f = { object o extends C; o} - val y: C = f - val x = f -} -- cgit v1.2.3 From c2d5246bdb33d60d3eaff62a539d01368124d859 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 7 May 2014 14:50:56 +0200 Subject: More systematic treatment of prototypes. There's a delicate balance about how much of a prototype should be passed down the tree when typechecking. Passing little can cause ambiguity errors (both in overloading and in implicit search). Passing too much can cause spurious errors because implicit conversions "down the road" that apply to some tree continaing the result might not be considered. Symptoms of the problems wree that we could not handle the tests included in this commit before. The new scheme is as follows: we always keep all available information in a prototype, but hide nested prototypes behined a `IgnoredProto` wall. These trees will not be considered for conformity checking. When type checking hits an ambiguity, it tries again with a prototype that's one level deeper (has fewer Ignore links) than the previous one. This continues until there are no more Ignore links to unwrap. We also generalize the scheme for wrapping qualifiers of select nodes from realApply to all instances where we compare against a FunProto. Finally, there are some fixes that avoid assertion violations that were provoked by the new typechecking scheme. --- src/dotty/tools/dotc/core/Types.scala | 10 ++++- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 12 +++--- src/dotty/tools/dotc/typer/Applications.scala | 44 ++++++++------------- src/dotty/tools/dotc/typer/Implicits.scala | 14 +++++-- src/dotty/tools/dotc/typer/ProtoTypes.scala | 41 +++++++++++++------ src/dotty/tools/dotc/typer/Typer.scala | 46 +++++++++++++++++----- test/dotc/tests.scala | 4 +- tests/pending/pos/t1693.scala | 9 ----- tests/pending/pos/t1832.scala | 10 ----- tests/pending/pos/t2060.scala | 44 --------------------- tests/pos/bigint.scala | 7 ++++ tests/pos/t1693.scala | 9 +++++ tests/pos/t1832.scala | 10 +++++ tests/pos/t2060.scala | 44 +++++++++++++++++++++ 14 files changed, 180 insertions(+), 124 deletions(-) delete mode 100644 tests/pending/pos/t1693.scala delete mode 100644 tests/pending/pos/t1832.scala delete mode 100755 tests/pending/pos/t2060.scala create mode 100644 tests/pos/bigint.scala create mode 100644 tests/pos/t1693.scala create mode 100644 tests/pos/t1832.scala create mode 100755 tests/pos/t2060.scala (limited to 'tests/pos') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 088a2e3af..36b546230 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -756,6 +756,11 @@ object Types { def typeParamNamed(name: TypeName)(implicit ctx: Context): Symbol = classSymbol.decls.lookup(name) orElse member(name).symbol + /** If this is a prototype with some ignored component, reveal one more + * layer of it. Otherwise the type itself. + */ + def deepenProto(implicit ctx: Context): Type = this + // ----- Substitutions ----------------------------------------------------- /** Substitute all types that refer in their symbol attribute to @@ -1057,12 +1062,13 @@ object Types { if (owner.isTerm) d else d.asSeenFrom(prefix) } - private def checkSymAssign(sym: Symbol) = + private def checkSymAssign(sym: Symbol)(implicit ctx: Context) = assert( (lastSymbol eq sym) || (lastSymbol eq null) || (lastSymbol.defRunId != sym.defRunId) || - (lastSymbol.defRunId == NoRunId), + (lastSymbol.defRunId == NoRunId) || + (lastSymbol.infoOrCompleter == ErrorType), s"data race? overwriting symbol of $this / ${this.getClass} / ${lastSymbol.id} / ${sym.id}") protected def sig: Signature = Signature.NotAMethod diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index dd8f04d92..c20598bb3 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} +import typer.ProtoTypes.{SelectionProto, ViewProto, FunProto, IgnoredProto} import Trees._ import scala.annotation.switch @@ -108,10 +108,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } return (toTextLocal(tycon) ~ "[" ~ Text(args map argText, ", ") ~ "]").close } - case tp: SelectionProto => - return toText(RefinedType(WildcardType, tp.name, tp.memberProto)) - case tp: ViewProto => - return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType) case tp: TypeRef => if ((tp.symbol is TypeParam | TypeArgument) && !ctx.phase.erasedTypes) { return tp.info match { @@ -121,8 +117,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } case ExprType(result) => return "=> " ~ toText(result) + case tp: SelectionProto => + return toText(RefinedType(WildcardType, tp.name, tp.memberProto)) + case tp: ViewProto => + return toText(tp.argType) ~ " ?=>? " ~ toText(tp.resultType) case FunProto(args, resultType, _) => return "funproto(" ~ toTextGlobal(args, ", ") ~ "):" ~ toText(resultType) + case tp: IgnoredProto => + return "?" case _ => } super.toText(tp) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 0f47336fc..92acb7939 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -434,7 +434,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, pt, this) + var proto = new FunProto(tree.args, ignoreIfProto(pt), this) val fun1 = typedExpr(tree.fun, proto) // Warning: The following line is dirty and fragile. We record that auto-tupling was demanded as @@ -453,30 +453,13 @@ trait Applications extends Compatibility { self: Typer => else new ApplyToUntyped(tree, fun1, funRef, proto, pt) val result = app.result ConstFold(result) - } { (failedVal, failedState) => fun1 match { - case Select(qual, name) => - // try with prototype `[].name(args)`, this might succeed by inserting an - // implicit conversion around []. (an example is Int + BigInt). - tryEither { implicit ctx => - val simpleFunProto = new FunProto(tree.args, WildcardType, this) // drop result type, because views are disabled - val selProto = SelectionProto(name, simpleFunProto, NoViewsAllowed) - val qual1 = adaptInterpolated(qual, selProto) - if (qual eq qual1) ctx.error("no progress") - if (ctx.reporter.hasErrors) qual1 - else - typedApply( - cpy.Apply(tree, - cpy.Select(fun1, untpd.TypedSplice(qual1), name), - proto.typedArgs map untpd.TypedSplice), - pt) - } { (_, _) => - failedState.commit() - failedVal - } - case _ => - failedState.commit() - failedVal - } + } { (failedVal, failedState) => + val fun2 = tryInsertImplicit(fun1, proto) + if (fun1 eq fun2) { + failedState.commit() + failedVal + } else typedApply( + cpy.Apply(tree, untpd.TypedSplice(fun2), proto.typedArgs map untpd.TypedSplice), pt) } case _ => fun1.tpe match { @@ -771,7 +754,7 @@ trait Applications extends Compatibility { self: Typer => def isAsSpecific(alt1: TermRef, tp1: Type, alt2: TermRef, tp2: Type): Boolean = ctx.traceIndented(i"isAsSpecific $tp1 $tp2", overload) { tp1 match { case tp1: PolyType => def bounds(tparamRefs: List[TypeRef]) = tp1.paramBounds map (_.substParams(tp1, tparamRefs)) - val tparams = ctx.newTypeParams(alt1.symbol.owner, tp1.paramNames, EmptyFlags, bounds) + val tparams = ctx.newTypeParams(alt1.symbol, tp1.paramNames, EmptyFlags, bounds) isAsSpecific(alt1, tp1.instantiate(tparams map (_.typeRef)), alt2, tp2) case tp1: MethodType => def repeatedToSingle(tp: Type) = if (tp.isRepeatedParam) tp.argTypesHi.head else tp @@ -927,7 +910,14 @@ trait Applications extends Compatibility { self: Typer => alts filter (normalizedCompatible(_, pt)) } if (isDetermined(candidates)) candidates - else narrowMostSpecific(candidates) + else narrowMostSpecific(candidates) match { + case result @ (alt1 :: alt2 :: _) => + val deepPt = pt.deepenProto + if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs) + else result + case result => + result + } } } diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index a32f552ed..d2a94e287 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -368,7 +368,10 @@ trait Implicits { self: Typer => return defn.isValueSubClass(from.symbol, to.symbol) case _ => } + case from: ValueType => + ; case _ => + return false } inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess] } @@ -410,12 +413,15 @@ trait Implicits { self: Typer => else new ImplicitSearch(pt, argument, pos) val result = isearch.bestImplicit result match { - case success: SearchSuccess => - // println(s"committing to ${success.tstate.show}") - success.tstate.commit() + case result: SearchSuccess => + result.tstate.commit() + result + case result: AmbiguousImplicits => + val deepPt = pt.deepenProto + if (deepPt ne pt) inferImplicit(deepPt, argument, pos) else result case _ => + result } - result } } diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index fab652849..1438f9e16 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -71,6 +71,23 @@ object ProtoTypes { override def viewExists(tp: Type, pt: Type)(implicit ctx: Context): Boolean = false } + /** A trait for prototypes that match all types */ + trait MatchAlways extends ProtoType { + def isMatchedBy(tp1: Type)(implicit ctx: Context) = true + def map(tm: TypeMap)(implicit ctx: Context): ProtoType = this + def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = x + } + + /** 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 + } + + 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 @@ -107,6 +124,8 @@ object ProtoTypes { def map(tm: TypeMap)(implicit ctx: Context) = derivedSelectionProto(name, tm(memberProto), compat) def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context) = ta(x, memberProto) + override def deepenProto(implicit ctx: Context) = derivedSelectionProto(name, memberProto.deepenProto, compat) + override def computeHash = addDelta(doHash(name, memberProto), if (compat eq NoViewsAllowed) 1 else 0) } @@ -126,8 +145,7 @@ object ProtoTypes { if (name.isConstructorName) WildcardType else tp match { case tp: UnapplyFunProto => new UnapplySelectionProto(name) - case tp: ProtoType => SelectionProto(name, WildcardType, typer) - case _ => SelectionProto(name, tp, typer) + case tp => SelectionProto(name, ignoreIfProto(tp), typer) } /** A prototype for expressions [] that are in some unspecified selection operation @@ -208,7 +226,10 @@ object ProtoTypes { def map(tm: TypeMap)(implicit ctx: Context): FunProto = derivedFunProto(args, tm(resultType), typer) - def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = ta(x, resultType) + def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = + ta(ta.foldOver(x, typedArgs.tpes), resultType) + + override def deepenProto(implicit ctx: Context) = derivedFunProto(args, resultType.deepenProto, typer) } /** A prototype for implicitly inferred views: @@ -226,10 +247,10 @@ object ProtoTypes { def map(tm: TypeMap)(implicit ctx: Context): ViewProto = derivedViewProto(tm(argType), tm(resultType)) - def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = ta(ta(x, argType), resultType) + def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = + ta(ta(x, argType), resultType) - override def namedPartsWith(p: NamedType => Boolean)(implicit ctx: Context): collection.Set[NamedType] = - AndType.unchecked(argType, resultType).namedPartsWith(p) // this is more efficient than oring two namedParts sets + override def deepenProto(implicit ctx: Context) = derivedViewProto(argType, resultType.deepenProto) } class CachedViewProto(argType: Type, resultType: Type)(implicit ctx: Context) extends ViewProto(argType, resultType) { @@ -266,17 +287,15 @@ object ProtoTypes { def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context): T = ta(ta.foldOver(x, targs), resultType) + + override def deepenProto(implicit ctx: Context) = derivedPolyProto(targs, resultType.deepenProto) } /** A prototype for expressions [] that are known to be functions: * * [] _ */ - object AnyFunctionProto extends UncachedGroundType with ProtoType { - def isMatchedBy(tp: Type)(implicit ctx: Context) = true - def map(tm: TypeMap)(implicit ctx: Context) = this - def fold[T](x: T, ta: TypeAccumulator[T])(implicit ctx: Context) = x - } + object AnyFunctionProto extends UncachedGroundType with MatchAlways /** Add all parameters in given polytype `pt` to the constraint's domain. * If the constraint contains already some of these parameters in its domain, diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 944b44510..5d477193c 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1009,15 +1009,41 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - def tryInsertApply(tree: Tree, pt: Type)(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) - } { - fallBack + /** 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`. + */ + 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) + if (tree1 eq tree) fallBack(failedTree, failedState) + else adapt(tree1, pt) } + /** 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) + 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)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ { /*>|>*/ ctx.traceIndented(i"adapting $tree of type ${tree.tpe} to $pt", typr, show = true) /*<|<*/ { interpolateUndetVars(tree) @@ -1087,7 +1113,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def hasEmptyParams(denot: SingleDenotation) = denot.info.paramTypess == ListOfNil pt match { case pt: FunProto => - tryInsertApply(tree, pt)((_, _) => noMatches) + tryInsertApplyOrImplicit(tree, pt)((_, _) => noMatches) case _ => if (altDenots exists (_.info.paramTypess == ListOfNil)) typed(untpd.Apply(untpd.TypedSplice(tree), Nil), pt) @@ -1113,7 +1139,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit adaptToArgs(wtp, pt.tupled) else tree - case _ => tryInsertApply(tree, pt) { + case _ => tryInsertApplyOrImplicit(tree, pt) { val more = tree match { case Apply(_, _) => " more" case _ => "" @@ -1216,7 +1242,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case pt: FunProto => adaptToArgs(wtp, pt) case pt: PolyProto => - tryInsertApply(tree, pt) { + tryInsertApplyOrImplicit(tree, pt) { (_, _) => tree // error will be reported in typedTypeApply } case _ => diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 9a173a5ce..4acf8374e 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -64,8 +64,8 @@ class tests extends CompilerTest { @Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2) @Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2) @Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3) - @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", "-language:noAutoTupling" :: Nil, xerrors = 3) - @Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 3) + @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", "-language:noAutoTupling" :: Nil, xerrors = 4) + @Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 4) @Test def neg_companions = compileFile(negDir, "companions", xerrors = 1) @Test def neg_i39 = compileFile(negDir, "i39", xerrors = 1) @Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 4) diff --git a/tests/pending/pos/t1693.scala b/tests/pending/pos/t1693.scala deleted file mode 100644 index 881bf89a0..000000000 --- a/tests/pending/pos/t1693.scala +++ /dev/null @@ -1,9 +0,0 @@ -object Test { - class Foo - class SomeOps(x : Foo) { def foo(x: String) = 1 } - class OtherOps(x : Foo) { def foo(x: Int) = 1 } - implicit def mkSomeOps(x: Foo) : SomeOps = new SomeOps(x) - implicit def mkOtherOps(x: Foo) : OtherOps = new OtherOps(x) - - (new Foo).foo(1) -} diff --git a/tests/pending/pos/t1832.scala b/tests/pending/pos/t1832.scala deleted file mode 100644 index 9ad9703c2..000000000 --- a/tests/pending/pos/t1832.scala +++ /dev/null @@ -1,10 +0,0 @@ -trait Cloning { - trait Foo - def fn(g: Any => Unit): Foo - - class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo } - - implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null } - - val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } -} diff --git a/tests/pending/pos/t2060.scala b/tests/pending/pos/t2060.scala deleted file mode 100755 index 0b9079062..000000000 --- a/tests/pending/pos/t2060.scala +++ /dev/null @@ -1,44 +0,0 @@ -/* The problem here is that we cannot insert an implicit to - * add a polymorphic method which is then instantiated to the - * right type. When searching for the implicit in the `fails to compile - * line': - * - * val failure = 1.0 + new Op[Int] - * - * we reduce the problem to finding a function from Double to - * {+: _ >: Op[Int] <: Any}, that is, a method which takes - * an argument which is an Op[Int] or a supertype thereof. - * Class Rich is not a subtype of this structural record, because - * polymorphic method instantiation is not contained in subtyping. - * That is: The method type [I](op : Op[I]): Op[I] is not a subtype - * of (Op[Int]): Op[Int]. - * At present it is unclear whether this problem can be solved. - */ -object Test { - class Op[I]; - class IntOp extends Op[Int]; - - class Rich(x : Double) { - def + (op : IntOp): IntOp = op; - def + [I](op : Op[I]): Op[I] = op; - def plus [I](op : Op[I]): Op[I] = op; - } - - implicit def iToRich(x : Double): Test.Rich = - new Rich(x); - - // fails to compile - val x = 1.0 + new Op[Int] - - // works as expected -- - // problem isn't in adding new "+" - val a = 1.0 + new IntOp; - - // works as expected -- - // problem isn't in binding type variable I - val b = 1.0 plus new Op[Int]; - - // works as expected -- - // problem isn't in using Rich.+[I](op : Op[I]) - val c = iToRich(1.0) + new Op[Int]; -} diff --git a/tests/pos/bigint.scala b/tests/pos/bigint.scala new file mode 100644 index 000000000..e1aaaf96e --- /dev/null +++ b/tests/pos/bigint.scala @@ -0,0 +1,7 @@ +import scala.math.BigInt +//import BigInt._ +object test { + + 1 * BigInt(0) + +} diff --git a/tests/pos/t1693.scala b/tests/pos/t1693.scala new file mode 100644 index 000000000..881bf89a0 --- /dev/null +++ b/tests/pos/t1693.scala @@ -0,0 +1,9 @@ +object Test { + class Foo + class SomeOps(x : Foo) { def foo(x: String) = 1 } + class OtherOps(x : Foo) { def foo(x: Int) = 1 } + implicit def mkSomeOps(x: Foo) : SomeOps = new SomeOps(x) + implicit def mkOtherOps(x: Foo) : OtherOps = new OtherOps(x) + + (new Foo).foo(1) +} diff --git a/tests/pos/t1832.scala b/tests/pos/t1832.scala new file mode 100644 index 000000000..9ad9703c2 --- /dev/null +++ b/tests/pos/t1832.scala @@ -0,0 +1,10 @@ +trait Cloning { + trait Foo + def fn(g: Any => Unit): Foo + + class Star { def *(a: Cloning.this.Foo): Cloning.this.Foo } + + implicit def mkStar(i: Int): Star = new Star { def *(a: Foo): Foo = null } + + val pool = 4 * fn { case ghostSYMBOL: Int => ghostSYMBOL * 2 } +} diff --git a/tests/pos/t2060.scala b/tests/pos/t2060.scala new file mode 100755 index 000000000..0b9079062 --- /dev/null +++ b/tests/pos/t2060.scala @@ -0,0 +1,44 @@ +/* The problem here is that we cannot insert an implicit to + * add a polymorphic method which is then instantiated to the + * right type. When searching for the implicit in the `fails to compile + * line': + * + * val failure = 1.0 + new Op[Int] + * + * we reduce the problem to finding a function from Double to + * {+: _ >: Op[Int] <: Any}, that is, a method which takes + * an argument which is an Op[Int] or a supertype thereof. + * Class Rich is not a subtype of this structural record, because + * polymorphic method instantiation is not contained in subtyping. + * That is: The method type [I](op : Op[I]): Op[I] is not a subtype + * of (Op[Int]): Op[Int]. + * At present it is unclear whether this problem can be solved. + */ +object Test { + class Op[I]; + class IntOp extends Op[Int]; + + class Rich(x : Double) { + def + (op : IntOp): IntOp = op; + def + [I](op : Op[I]): Op[I] = op; + def plus [I](op : Op[I]): Op[I] = op; + } + + implicit def iToRich(x : Double): Test.Rich = + new Rich(x); + + // fails to compile + val x = 1.0 + new Op[Int] + + // works as expected -- + // problem isn't in adding new "+" + val a = 1.0 + new IntOp; + + // works as expected -- + // problem isn't in binding type variable I + val b = 1.0 plus new Op[Int]; + + // works as expected -- + // problem isn't in using Rich.+[I](op : Op[I]) + val c = iToRich(1.0) + new Op[Int]; +} -- cgit v1.2.3 From 27081ae59ba5b00b6ae05bb3cdd9c3ff7db0a28e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 7 May 2014 19:09:52 +0200 Subject: Tests pos/23xx to 24xx. --- tests/disabled/java-interop/pos/t2377/Q.java | 12 +++++++ tests/disabled/java-interop/pos/t2377/a.scala | 8 +++++ tests/disabled/java-interop/pos/t2409/J.java | 4 +++ tests/disabled/java-interop/pos/t2409/t2409.scala | 1 + .../disabled/java-interop/pos/t2413/TestJava.java | 7 ++++ .../java-interop/pos/t2413/TestScalac.scala | 23 +++++++++++++ tests/disabled/java-interop/pos/t2433/A.java | 4 +++ tests/disabled/java-interop/pos/t2433/B.java | 4 +++ tests/disabled/java-interop/pos/t2433/Test.scala | 3 ++ tests/disabled/java-interop/pos/t2464/JavaOne.java | 5 +++ .../java-interop/pos/t2464/ScalaOne_1.scala | 6 ++++ .../disabled/java-interop/pos/t2464/t2464_2.scala | 3 ++ tests/new/t2405.scala | 23 +++++++++++++ tests/new/t2421.scala | 14 ++++++++ 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/t2429.scala | 25 ++++++++++++++ tests/pending/pos/t2454.scala | 25 ++++++++++++++ tests/pos/t2208_pos.scala | 8 +++++ tests/pos/t2234.scala | 4 +++ tests/pos/t2260.scala | 10 ++++++ tests/pos/t2261.scala | 9 +++++ tests/pos/t229.scala | 3 ++ tests/pos/t2293.scala | 5 +++ tests/pos/t2305.scala | 26 +++++++++++++++ tests/pos/t2310.scala | 38 ++++++++++++++++++++++ tests/pos/t2331.scala | 11 +++++++ tests/pos/t2399.scala | 14 ++++++++ tests/untried/pos/t2208_pos.scala | 8 ----- tests/untried/pos/t2234.scala | 4 --- tests/untried/pos/t2260.scala | 10 ------ tests/untried/pos/t2261.scala | 9 ----- tests/untried/pos/t229.scala | 3 -- tests/untried/pos/t2293.scala | 5 --- tests/untried/pos/t2305.scala | 26 --------------- tests/untried/pos/t2310.scala | 38 ---------------------- tests/untried/pos/t2331.scala | 11 ------- tests/untried/pos/t2377/Q.java | 12 ------- tests/untried/pos/t2377/a.scala | 8 ----- tests/untried/pos/t2399.scala | 14 -------- tests/untried/pos/t2405.scala | 23 ------------- tests/untried/pos/t2409/J.java | 4 --- tests/untried/pos/t2409/t2409.scala | 1 - tests/untried/pos/t2413/TestJava.java | 7 ---- tests/untried/pos/t2413/TestScalac.scala | 23 ------------- tests/untried/pos/t2421.scala | 14 -------- tests/untried/pos/t2421_delitedsl.scala | 37 --------------------- tests/untried/pos/t2421b_pos.scala | 19 ----------- tests/untried/pos/t2421c.scala | 17 ---------- tests/untried/pos/t2425.scala | 15 --------- tests/untried/pos/t2429.scala | 25 -------------- tests/untried/pos/t2433/A.java | 4 --- tests/untried/pos/t2433/B.java | 4 --- tests/untried/pos/t2433/Test.scala | 3 -- tests/untried/pos/t2435.scala | 27 --------------- tests/untried/pos/t2441pos.scala | 8 ----- tests/untried/pos/t2444.scala | 15 --------- tests/untried/pos/t245.scala | 18 ---------- tests/untried/pos/t2454.scala | 25 -------------- tests/untried/pos/t2464/JavaOne.java | 5 --- tests/untried/pos/t2464/ScalaOne_1.scala | 6 ---- tests/untried/pos/t2464/t2464_2.scala | 3 -- tests/untried/pos/t247.scala | 26 --------------- tests/untried/pos/t2484.scala | 19 ----------- tests/untried/pos/t2486.scala | 3 -- 73 files changed, 462 insertions(+), 499 deletions(-) create mode 100644 tests/disabled/java-interop/pos/t2377/Q.java create mode 100644 tests/disabled/java-interop/pos/t2377/a.scala create mode 100644 tests/disabled/java-interop/pos/t2409/J.java create mode 100644 tests/disabled/java-interop/pos/t2409/t2409.scala create mode 100644 tests/disabled/java-interop/pos/t2413/TestJava.java create mode 100644 tests/disabled/java-interop/pos/t2413/TestScalac.scala create mode 100755 tests/disabled/java-interop/pos/t2433/A.java create mode 100755 tests/disabled/java-interop/pos/t2433/B.java create mode 100755 tests/disabled/java-interop/pos/t2433/Test.scala create mode 100644 tests/disabled/java-interop/pos/t2464/JavaOne.java create mode 100644 tests/disabled/java-interop/pos/t2464/ScalaOne_1.scala create mode 100644 tests/disabled/java-interop/pos/t2464/t2464_2.scala create mode 100644 tests/new/t2405.scala create mode 100644 tests/new/t2421.scala create mode 100644 tests/new/t2421b_pos.scala create mode 100644 tests/new/t2421c.scala create mode 100755 tests/new/t2425.scala create mode 100644 tests/new/t2435.scala create mode 100644 tests/new/t2441pos.scala create mode 100644 tests/new/t2444.scala create mode 100644 tests/new/t245.scala create mode 100644 tests/new/t247.scala create mode 100755 tests/new/t2484.scala create mode 100644 tests/new/t2486.scala create mode 100755 tests/pending/pos/t2429.scala create mode 100644 tests/pending/pos/t2454.scala create mode 100644 tests/pos/t2208_pos.scala create mode 100644 tests/pos/t2234.scala create mode 100644 tests/pos/t2260.scala create mode 100644 tests/pos/t2261.scala create mode 100644 tests/pos/t229.scala create mode 100644 tests/pos/t2293.scala create mode 100644 tests/pos/t2305.scala create mode 100644 tests/pos/t2310.scala create mode 100644 tests/pos/t2331.scala create mode 100644 tests/pos/t2399.scala delete mode 100644 tests/untried/pos/t2208_pos.scala delete mode 100644 tests/untried/pos/t2234.scala delete mode 100644 tests/untried/pos/t2260.scala delete mode 100644 tests/untried/pos/t2261.scala delete mode 100644 tests/untried/pos/t229.scala delete mode 100644 tests/untried/pos/t2293.scala delete mode 100644 tests/untried/pos/t2305.scala delete mode 100644 tests/untried/pos/t2310.scala delete mode 100644 tests/untried/pos/t2331.scala delete mode 100644 tests/untried/pos/t2377/Q.java delete mode 100644 tests/untried/pos/t2377/a.scala delete mode 100644 tests/untried/pos/t2399.scala delete mode 100644 tests/untried/pos/t2405.scala delete mode 100644 tests/untried/pos/t2409/J.java delete mode 100644 tests/untried/pos/t2409/t2409.scala delete mode 100644 tests/untried/pos/t2413/TestJava.java delete mode 100644 tests/untried/pos/t2413/TestScalac.scala delete mode 100644 tests/untried/pos/t2421.scala delete mode 100644 tests/untried/pos/t2421_delitedsl.scala delete mode 100644 tests/untried/pos/t2421b_pos.scala delete mode 100644 tests/untried/pos/t2421c.scala delete mode 100755 tests/untried/pos/t2425.scala delete mode 100755 tests/untried/pos/t2429.scala delete mode 100755 tests/untried/pos/t2433/A.java delete mode 100755 tests/untried/pos/t2433/B.java delete mode 100755 tests/untried/pos/t2433/Test.scala delete mode 100644 tests/untried/pos/t2435.scala delete mode 100644 tests/untried/pos/t2441pos.scala delete mode 100644 tests/untried/pos/t2444.scala delete mode 100644 tests/untried/pos/t245.scala delete mode 100644 tests/untried/pos/t2454.scala delete mode 100644 tests/untried/pos/t2464/JavaOne.java delete mode 100644 tests/untried/pos/t2464/ScalaOne_1.scala delete mode 100644 tests/untried/pos/t2464/t2464_2.scala delete mode 100644 tests/untried/pos/t247.scala delete mode 100755 tests/untried/pos/t2484.scala delete mode 100644 tests/untried/pos/t2486.scala (limited to 'tests/pos') diff --git a/tests/disabled/java-interop/pos/t2377/Q.java b/tests/disabled/java-interop/pos/t2377/Q.java new file mode 100644 index 000000000..e3d11c70e --- /dev/null +++ b/tests/disabled/java-interop/pos/t2377/Q.java @@ -0,0 +1,12 @@ +public final class Q { + public static final class Stage { + public static Builder newBuilder() { return new Builder(); } + public static final class Builder { } + public Builder toBuilder() { return newBuilder(); } + } + public static final class WorkUnit { + public static Builder newBuilder() { return new Builder(); } + public static final class Builder { } + public Builder toBuilder() { return newBuilder(); } + } +} diff --git a/tests/disabled/java-interop/pos/t2377/a.scala b/tests/disabled/java-interop/pos/t2377/a.scala new file mode 100644 index 000000000..bda59ce0d --- /dev/null +++ b/tests/disabled/java-interop/pos/t2377/a.scala @@ -0,0 +1,8 @@ +import Q._ + +class Bop(var workUnit: WorkUnit) { + def addStages(stageBuilder: Stage.Builder): Unit = { + val builder = workUnit.toBuilder + () + } +} diff --git a/tests/disabled/java-interop/pos/t2409/J.java b/tests/disabled/java-interop/pos/t2409/J.java new file mode 100644 index 000000000..6b7c45ff6 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2409/J.java @@ -0,0 +1,4 @@ +class J { + static class J2 { } + J(J2 j2) { } +} diff --git a/tests/disabled/java-interop/pos/t2409/t2409.scala b/tests/disabled/java-interop/pos/t2409/t2409.scala new file mode 100644 index 000000000..0412f7d82 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2409/t2409.scala @@ -0,0 +1 @@ +object S { new J(null) } diff --git a/tests/disabled/java-interop/pos/t2413/TestJava.java b/tests/disabled/java-interop/pos/t2413/TestJava.java new file mode 100644 index 000000000..252c01fbc --- /dev/null +++ b/tests/disabled/java-interop/pos/t2413/TestJava.java @@ -0,0 +1,7 @@ +package pack; + +public class TestJava { + protected String repeatParam(String ... items) { + return "nothing"; + } +} diff --git a/tests/disabled/java-interop/pos/t2413/TestScalac.scala b/tests/disabled/java-interop/pos/t2413/TestScalac.scala new file mode 100644 index 000000000..098e852dd --- /dev/null +++ b/tests/disabled/java-interop/pos/t2413/TestScalac.scala @@ -0,0 +1,23 @@ +import pack.TestJava + +class Foo extends TestJava { + + // THIS METHOD YIELDS TO CRASH +/* def foomethod : Option[String] => Unit = { + case None => + val path = repeatParam("s","a","b","c") + () + case Some(error) => + () + } + + // THIS IS OK + def foomethod2 : String = repeatParam("s","a"); + + // THIS IS OK + val aVal = repeatParam("1","2","3") */ + + // THIS YIELDS TO CRASH + for (a <- 1 to 4 ; anotherVal = repeatParam("1","2","3")) + yield anotherVal +} diff --git a/tests/disabled/java-interop/pos/t2433/A.java b/tests/disabled/java-interop/pos/t2433/A.java new file mode 100755 index 000000000..340690c40 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2433/A.java @@ -0,0 +1,4 @@ +class A223 extends B223.Inner { + static class Inner {} + void foo() {} +} \ No newline at end of file diff --git a/tests/disabled/java-interop/pos/t2433/B.java b/tests/disabled/java-interop/pos/t2433/B.java new file mode 100755 index 000000000..151dd71ca --- /dev/null +++ b/tests/disabled/java-interop/pos/t2433/B.java @@ -0,0 +1,4 @@ +class B223 { + static class Inner {} + void m(A223.Inner x) {} +} \ No newline at end of file diff --git a/tests/disabled/java-interop/pos/t2433/Test.scala b/tests/disabled/java-interop/pos/t2433/Test.scala new file mode 100755 index 000000000..02fd89b64 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2433/Test.scala @@ -0,0 +1,3 @@ +object Test { + (new A223).foo() +} diff --git a/tests/disabled/java-interop/pos/t2464/JavaOne.java b/tests/disabled/java-interop/pos/t2464/JavaOne.java new file mode 100644 index 000000000..ff36868a0 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2464/JavaOne.java @@ -0,0 +1,5 @@ +class ClassTwo { + public static class Child { + public void func2() {return ;} + } +} diff --git a/tests/disabled/java-interop/pos/t2464/ScalaOne_1.scala b/tests/disabled/java-interop/pos/t2464/ScalaOne_1.scala new file mode 100644 index 000000000..1caf8ecae --- /dev/null +++ b/tests/disabled/java-interop/pos/t2464/ScalaOne_1.scala @@ -0,0 +1,6 @@ +class ScalaClassOne extends ClassTwo.Child { + def func4() = { + func2 + } +} + diff --git a/tests/disabled/java-interop/pos/t2464/t2464_2.scala b/tests/disabled/java-interop/pos/t2464/t2464_2.scala new file mode 100644 index 000000000..13a52c952 --- /dev/null +++ b/tests/disabled/java-interop/pos/t2464/t2464_2.scala @@ -0,0 +1,3 @@ +object Test { + val c1 = new ScalaClassOne +} diff --git a/tests/new/t2405.scala b/tests/new/t2405.scala new file mode 100644 index 000000000..224b2ce83 --- /dev/null +++ b/tests/new/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/new/t2421.scala b/tests/new/t2421.scala new file mode 100644 index 000000000..2544a1cb3 --- /dev/null +++ b/tests/new/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/new/t2421b_pos.scala b/tests/new/t2421b_pos.scala new file mode 100644 index 000000000..679b8a8d6 --- /dev/null +++ b/tests/new/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/new/t2421c.scala b/tests/new/t2421c.scala new file mode 100644 index 000000000..bd24cacd7 --- /dev/null +++ b/tests/new/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/new/t2425.scala b/tests/new/t2425.scala new file mode 100755 index 000000000..477d5467a --- /dev/null +++ b/tests/new/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/new/t2435.scala b/tests/new/t2435.scala new file mode 100644 index 000000000..697e9e1f2 --- /dev/null +++ b/tests/new/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/new/t2441pos.scala b/tests/new/t2441pos.scala new file mode 100644 index 000000000..25eb2232c --- /dev/null +++ b/tests/new/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/new/t2444.scala b/tests/new/t2444.scala new file mode 100644 index 000000000..fac1e95d0 --- /dev/null +++ b/tests/new/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/new/t245.scala b/tests/new/t245.scala new file mode 100644 index 000000000..570ac4178 --- /dev/null +++ b/tests/new/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/new/t247.scala b/tests/new/t247.scala new file mode 100644 index 000000000..fdcafeb2c --- /dev/null +++ b/tests/new/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/new/t2484.scala b/tests/new/t2484.scala new file mode 100755 index 000000000..15165c247 --- /dev/null +++ b/tests/new/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/new/t2486.scala b/tests/new/t2486.scala new file mode 100644 index 000000000..69fe4c127 --- /dev/null +++ b/tests/new/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 => () } } diff --git a/tests/pending/pos/t2429.scala b/tests/pending/pos/t2429.scala new file mode 100755 index 000000000..4cda3bde1 --- /dev/null +++ b/tests/pending/pos/t2429.scala @@ -0,0 +1,25 @@ +object Msg { + trait T + + trait TSeq + + object TSeq { + implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") + } + + def render: Unit = { + val msgs: TSeq = (List[(Any, Any)]().flatMap { + case (a, b) => { + a match { + case _ => b match { + case _ => sys.error("stub") + } + } + } + } /*: Seq[T] Adding this type annotation avoids the compile error.*/) + } +} +object Oops { + implicit def someImplicit(s: Seq[_]): String = sys.error("stub") + def item: String = Nil map { case e: Any => e } +} diff --git a/tests/pending/pos/t2454.scala b/tests/pending/pos/t2454.scala new file mode 100644 index 000000000..00f2e6f67 --- /dev/null +++ b/tests/pending/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/t2208_pos.scala b/tests/pos/t2208_pos.scala new file mode 100644 index 000000000..dd6d686ba --- /dev/null +++ b/tests/pos/t2208_pos.scala @@ -0,0 +1,8 @@ +object Test { + class A + + class B[X] + type Alias[X <: A] = B[X] + + val foo: B[A] = new Alias[A] // check that type aliases can be instantiated +} diff --git a/tests/pos/t2234.scala b/tests/pos/t2234.scala new file mode 100644 index 000000000..218e9f5e5 --- /dev/null +++ b/tests/pos/t2234.scala @@ -0,0 +1,4 @@ +object Test extends App { + val res0 = 1 #:: Stream.empty + res0 match { case 1 #:: xs => xs } +} diff --git a/tests/pos/t2260.scala b/tests/pos/t2260.scala new file mode 100644 index 000000000..4e4cc5ab2 --- /dev/null +++ b/tests/pos/t2260.scala @@ -0,0 +1,10 @@ +package top + +class Text(val value: String) extends Ordered[Text] { + def compare(that: Text) = value.compare(that.value) +} + +object Index { + import scala.collection.immutable.TreeMap + val tree = TreeMap.empty[Text, String] +} diff --git a/tests/pos/t2261.scala b/tests/pos/t2261.scala new file mode 100644 index 000000000..06360d500 --- /dev/null +++ b/tests/pos/t2261.scala @@ -0,0 +1,9 @@ +class Bob[T] +object Test { + implicit def foo2bar[T](xs: List[T]): Bob[T] = new Bob[T] + var x: Bob[Int] = null + x = List(1,2,3) + // the problem here was that somehow the type variable that was used to infer the type argument for List.apply + // would accumulate several conflicting constraints + // can't reproduce with +} diff --git a/tests/pos/t229.scala b/tests/pos/t229.scala new file mode 100644 index 000000000..72ddfa74f --- /dev/null +++ b/tests/pos/t229.scala @@ -0,0 +1,3 @@ +class Test extends java.util.ArrayList[Object] { + override def add(index: Int, element: java.lang.Object): Unit = {} +} diff --git a/tests/pos/t2293.scala b/tests/pos/t2293.scala new file mode 100644 index 000000000..536d4ec3d --- /dev/null +++ b/tests/pos/t2293.scala @@ -0,0 +1,5 @@ +import scala.collection.JavaConversions._ + +object Test { + val m: java.util.Map[String,String] = collection.mutable.Map("1"->"2") +} diff --git a/tests/pos/t2305.scala b/tests/pos/t2305.scala new file mode 100644 index 000000000..3338ab911 --- /dev/null +++ b/tests/pos/t2305.scala @@ -0,0 +1,26 @@ +import java.util.ArrayList + +trait Bind[Z[_]] + +class MySerializable[X] extends java.io.Serializable + +object Bind { + implicit val JavaArrayListBind: Bind[ArrayList] = new Bind[ArrayList] {} + implicit val MySerializableBind: Bind[MySerializable] = new Bind[MySerializable] {} +} + +object works { + // this works fine: + def runbind(implicit bind: Bind[MySerializable]): Unit = {} + runbind +} + +object breaks { + def runbind(implicit bind: Bind[ArrayList]): Unit = {} + runbind + /*java.lang.AssertionError: assertion failed: java.io.Serializable + at scala.Predef$.assert(Predef.scala:107) + at scala.tools.nsc.symtab.Types$TypeRef.transform(Types.scala:1417) + at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1559) + */ +} diff --git a/tests/pos/t2310.scala b/tests/pos/t2310.scala new file mode 100644 index 000000000..68912b496 --- /dev/null +++ b/tests/pos/t2310.scala @@ -0,0 +1,38 @@ +import scala.Stream._ + +object consistencyError { + /* this gives an error: + Consistency problem compiling (virtual file)! + Trying to call method body%1(List(scala.collection.immutable.Stream[A])) with arguments (List(tp2, temp6, temp5)) + case (l #:: ls, rs) => None + ^ + scala.tools.nsc.symtab.Types$TypeError: too many arguments for method body%1: (val rs: scala.collection.immutable.Stream[A])None.type + + two errors found + vss(0) = + args = List(tp2, temp6, temp5) + vss(1) = value rs, value ls, value l + args = List(tp2, temp6, temp5) + targets(0) = FinalState(,scala.None) + targets(1) = FinalState(,scala.None) + labels(1) = method body%1 + labels(0) = method body%0 + bx = 1 + label.tpe = (val rs: scala.collection.immutable.Stream[A])None.type + */ + def crash[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + case (Stream.Empty, Stream.Empty) => None + case (l #:: ls, rs) => None + } + + // These work + // def works1[A](lefts: Stream[A]) = lefts match { + // case Stream.Empty => None + // case l #:: ls => None + // } + // + // def works2[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { + // case (Stream.Empty, Stream.Empty) => None + // case (ls, rs) => None + // } +} diff --git a/tests/pos/t2331.scala b/tests/pos/t2331.scala new file mode 100644 index 000000000..a7f80ac98 --- /dev/null +++ b/tests/pos/t2331.scala @@ -0,0 +1,11 @@ +trait C { + def m[T]: T +} + +object Test { + val o /*: C --> no crash*/ = new C { + def m[T]: Nothing /*: T --> no crash*/ = sys.error("omitted") + } + + o.m[Nothing] +} diff --git a/tests/pos/t2399.scala b/tests/pos/t2399.scala new file mode 100644 index 000000000..a99998a0a --- /dev/null +++ b/tests/pos/t2399.scala @@ -0,0 +1,14 @@ +trait That1[A] +trait That2[A, R <: That2[A, R]] + +trait T[A, This >: Null <: That1[A] with T[A, This]] extends That2[A, This] { + self: This => + + private var next: This = _ + def isEmpty = next eq null + + def length: Int = { + def loop(x: This, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) + loop(self, 0) + } +} diff --git a/tests/untried/pos/t2208_pos.scala b/tests/untried/pos/t2208_pos.scala deleted file mode 100644 index dd6d686ba..000000000 --- a/tests/untried/pos/t2208_pos.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - class A - - class B[X] - type Alias[X <: A] = B[X] - - val foo: B[A] = new Alias[A] // check that type aliases can be instantiated -} diff --git a/tests/untried/pos/t2234.scala b/tests/untried/pos/t2234.scala deleted file mode 100644 index 218e9f5e5..000000000 --- a/tests/untried/pos/t2234.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test extends App { - val res0 = 1 #:: Stream.empty - res0 match { case 1 #:: xs => xs } -} diff --git a/tests/untried/pos/t2260.scala b/tests/untried/pos/t2260.scala deleted file mode 100644 index 4e4cc5ab2..000000000 --- a/tests/untried/pos/t2260.scala +++ /dev/null @@ -1,10 +0,0 @@ -package top - -class Text(val value: String) extends Ordered[Text] { - def compare(that: Text) = value.compare(that.value) -} - -object Index { - import scala.collection.immutable.TreeMap - val tree = TreeMap.empty[Text, String] -} diff --git a/tests/untried/pos/t2261.scala b/tests/untried/pos/t2261.scala deleted file mode 100644 index 06360d500..000000000 --- a/tests/untried/pos/t2261.scala +++ /dev/null @@ -1,9 +0,0 @@ -class Bob[T] -object Test { - implicit def foo2bar[T](xs: List[T]): Bob[T] = new Bob[T] - var x: Bob[Int] = null - x = List(1,2,3) - // the problem here was that somehow the type variable that was used to infer the type argument for List.apply - // would accumulate several conflicting constraints - // can't reproduce with -} diff --git a/tests/untried/pos/t229.scala b/tests/untried/pos/t229.scala deleted file mode 100644 index 72ddfa74f..000000000 --- a/tests/untried/pos/t229.scala +++ /dev/null @@ -1,3 +0,0 @@ -class Test extends java.util.ArrayList[Object] { - override def add(index: Int, element: java.lang.Object): Unit = {} -} diff --git a/tests/untried/pos/t2293.scala b/tests/untried/pos/t2293.scala deleted file mode 100644 index 536d4ec3d..000000000 --- a/tests/untried/pos/t2293.scala +++ /dev/null @@ -1,5 +0,0 @@ -import scala.collection.JavaConversions._ - -object Test { - val m: java.util.Map[String,String] = collection.mutable.Map("1"->"2") -} diff --git a/tests/untried/pos/t2305.scala b/tests/untried/pos/t2305.scala deleted file mode 100644 index 3338ab911..000000000 --- a/tests/untried/pos/t2305.scala +++ /dev/null @@ -1,26 +0,0 @@ -import java.util.ArrayList - -trait Bind[Z[_]] - -class MySerializable[X] extends java.io.Serializable - -object Bind { - implicit val JavaArrayListBind: Bind[ArrayList] = new Bind[ArrayList] {} - implicit val MySerializableBind: Bind[MySerializable] = new Bind[MySerializable] {} -} - -object works { - // this works fine: - def runbind(implicit bind: Bind[MySerializable]): Unit = {} - runbind -} - -object breaks { - def runbind(implicit bind: Bind[ArrayList]): Unit = {} - runbind - /*java.lang.AssertionError: assertion failed: java.io.Serializable - at scala.Predef$.assert(Predef.scala:107) - at scala.tools.nsc.symtab.Types$TypeRef.transform(Types.scala:1417) - at scala.tools.nsc.symtab.Types$TypeRef.baseType(Types.scala:1559) - */ -} diff --git a/tests/untried/pos/t2310.scala b/tests/untried/pos/t2310.scala deleted file mode 100644 index 68912b496..000000000 --- a/tests/untried/pos/t2310.scala +++ /dev/null @@ -1,38 +0,0 @@ -import scala.Stream._ - -object consistencyError { - /* this gives an error: - Consistency problem compiling (virtual file)! - Trying to call method body%1(List(scala.collection.immutable.Stream[A])) with arguments (List(tp2, temp6, temp5)) - case (l #:: ls, rs) => None - ^ - scala.tools.nsc.symtab.Types$TypeError: too many arguments for method body%1: (val rs: scala.collection.immutable.Stream[A])None.type - - two errors found - vss(0) = - args = List(tp2, temp6, temp5) - vss(1) = value rs, value ls, value l - args = List(tp2, temp6, temp5) - targets(0) = FinalState(,scala.None) - targets(1) = FinalState(,scala.None) - labels(1) = method body%1 - labels(0) = method body%0 - bx = 1 - label.tpe = (val rs: scala.collection.immutable.Stream[A])None.type - */ - def crash[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { - case (Stream.Empty, Stream.Empty) => None - case (l #:: ls, rs) => None - } - - // These work - // def works1[A](lefts: Stream[A]) = lefts match { - // case Stream.Empty => None - // case l #:: ls => None - // } - // - // def works2[A](lefts: Stream[A], rights: Stream[A]) = (lefts, rights) match { - // case (Stream.Empty, Stream.Empty) => None - // case (ls, rs) => None - // } -} diff --git a/tests/untried/pos/t2331.scala b/tests/untried/pos/t2331.scala deleted file mode 100644 index a7f80ac98..000000000 --- a/tests/untried/pos/t2331.scala +++ /dev/null @@ -1,11 +0,0 @@ -trait C { - def m[T]: T -} - -object Test { - val o /*: C --> no crash*/ = new C { - def m[T]: Nothing /*: T --> no crash*/ = sys.error("omitted") - } - - o.m[Nothing] -} diff --git a/tests/untried/pos/t2377/Q.java b/tests/untried/pos/t2377/Q.java deleted file mode 100644 index e3d11c70e..000000000 --- a/tests/untried/pos/t2377/Q.java +++ /dev/null @@ -1,12 +0,0 @@ -public final class Q { - public static final class Stage { - public static Builder newBuilder() { return new Builder(); } - public static final class Builder { } - public Builder toBuilder() { return newBuilder(); } - } - public static final class WorkUnit { - public static Builder newBuilder() { return new Builder(); } - public static final class Builder { } - public Builder toBuilder() { return newBuilder(); } - } -} diff --git a/tests/untried/pos/t2377/a.scala b/tests/untried/pos/t2377/a.scala deleted file mode 100644 index bda59ce0d..000000000 --- a/tests/untried/pos/t2377/a.scala +++ /dev/null @@ -1,8 +0,0 @@ -import Q._ - -class Bop(var workUnit: WorkUnit) { - def addStages(stageBuilder: Stage.Builder): Unit = { - val builder = workUnit.toBuilder - () - } -} diff --git a/tests/untried/pos/t2399.scala b/tests/untried/pos/t2399.scala deleted file mode 100644 index a99998a0a..000000000 --- a/tests/untried/pos/t2399.scala +++ /dev/null @@ -1,14 +0,0 @@ -trait That1[A] -trait That2[A, R <: That2[A, R]] - -trait T[A, This >: Null <: That1[A] with T[A, This]] extends That2[A, This] { - self: This => - - private var next: This = _ - def isEmpty = next eq null - - def length: Int = { - def loop(x: This, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) - loop(self, 0) - } -} diff --git a/tests/untried/pos/t2405.scala b/tests/untried/pos/t2405.scala deleted file mode 100644 index 224b2ce83..000000000 --- a/tests/untried/pos/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/untried/pos/t2409/J.java b/tests/untried/pos/t2409/J.java deleted file mode 100644 index 6b7c45ff6..000000000 --- a/tests/untried/pos/t2409/J.java +++ /dev/null @@ -1,4 +0,0 @@ -class J { - static class J2 { } - J(J2 j2) { } -} diff --git a/tests/untried/pos/t2409/t2409.scala b/tests/untried/pos/t2409/t2409.scala deleted file mode 100644 index 0412f7d82..000000000 --- a/tests/untried/pos/t2409/t2409.scala +++ /dev/null @@ -1 +0,0 @@ -object S { new J(null) } diff --git a/tests/untried/pos/t2413/TestJava.java b/tests/untried/pos/t2413/TestJava.java deleted file mode 100644 index 252c01fbc..000000000 --- a/tests/untried/pos/t2413/TestJava.java +++ /dev/null @@ -1,7 +0,0 @@ -package pack; - -public class TestJava { - protected String repeatParam(String ... items) { - return "nothing"; - } -} diff --git a/tests/untried/pos/t2413/TestScalac.scala b/tests/untried/pos/t2413/TestScalac.scala deleted file mode 100644 index 098e852dd..000000000 --- a/tests/untried/pos/t2413/TestScalac.scala +++ /dev/null @@ -1,23 +0,0 @@ -import pack.TestJava - -class Foo extends TestJava { - - // THIS METHOD YIELDS TO CRASH -/* def foomethod : Option[String] => Unit = { - case None => - val path = repeatParam("s","a","b","c") - () - case Some(error) => - () - } - - // THIS IS OK - def foomethod2 : String = repeatParam("s","a"); - - // THIS IS OK - val aVal = repeatParam("1","2","3") */ - - // THIS YIELDS TO CRASH - for (a <- 1 to 4 ; anotherVal = repeatParam("1","2","3")) - yield anotherVal -} diff --git a/tests/untried/pos/t2421.scala b/tests/untried/pos/t2421.scala deleted file mode 100644 index 2544a1cb3..000000000 --- a/tests/untried/pos/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/untried/pos/t2421_delitedsl.scala b/tests/untried/pos/t2421_delitedsl.scala deleted file mode 100644 index 2580592d9..000000000 --- a/tests/untried/pos/t2421_delitedsl.scala +++ /dev/null @@ -1,37 +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(DeliteInt(_: Int)) - - 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/untried/pos/t2421b_pos.scala b/tests/untried/pos/t2421b_pos.scala deleted file mode 100644 index 679b8a8d6..000000000 --- a/tests/untried/pos/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/untried/pos/t2421c.scala b/tests/untried/pos/t2421c.scala deleted file mode 100644 index bd24cacd7..000000000 --- a/tests/untried/pos/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/untried/pos/t2425.scala b/tests/untried/pos/t2425.scala deleted file mode 100755 index 477d5467a..000000000 --- a/tests/untried/pos/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/untried/pos/t2429.scala b/tests/untried/pos/t2429.scala deleted file mode 100755 index 4cda3bde1..000000000 --- a/tests/untried/pos/t2429.scala +++ /dev/null @@ -1,25 +0,0 @@ -object Msg { - trait T - - trait TSeq - - object TSeq { - implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") - } - - def render: Unit = { - val msgs: TSeq = (List[(Any, Any)]().flatMap { - case (a, b) => { - a match { - case _ => b match { - case _ => sys.error("stub") - } - } - } - } /*: Seq[T] Adding this type annotation avoids the compile error.*/) - } -} -object Oops { - implicit def someImplicit(s: Seq[_]): String = sys.error("stub") - def item: String = Nil map { case e: Any => e } -} diff --git a/tests/untried/pos/t2433/A.java b/tests/untried/pos/t2433/A.java deleted file mode 100755 index 340690c40..000000000 --- a/tests/untried/pos/t2433/A.java +++ /dev/null @@ -1,4 +0,0 @@ -class A223 extends B223.Inner { - static class Inner {} - void foo() {} -} \ No newline at end of file diff --git a/tests/untried/pos/t2433/B.java b/tests/untried/pos/t2433/B.java deleted file mode 100755 index 151dd71ca..000000000 --- a/tests/untried/pos/t2433/B.java +++ /dev/null @@ -1,4 +0,0 @@ -class B223 { - static class Inner {} - void m(A223.Inner x) {} -} \ No newline at end of file diff --git a/tests/untried/pos/t2433/Test.scala b/tests/untried/pos/t2433/Test.scala deleted file mode 100755 index 02fd89b64..000000000 --- a/tests/untried/pos/t2433/Test.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - (new A223).foo() -} diff --git a/tests/untried/pos/t2435.scala b/tests/untried/pos/t2435.scala deleted file mode 100644 index 697e9e1f2..000000000 --- a/tests/untried/pos/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/untried/pos/t2441pos.scala b/tests/untried/pos/t2441pos.scala deleted file mode 100644 index 25eb2232c..000000000 --- a/tests/untried/pos/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/untried/pos/t2444.scala b/tests/untried/pos/t2444.scala deleted file mode 100644 index fac1e95d0..000000000 --- a/tests/untried/pos/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/untried/pos/t245.scala b/tests/untried/pos/t245.scala deleted file mode 100644 index 570ac4178..000000000 --- a/tests/untried/pos/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/untried/pos/t2454.scala b/tests/untried/pos/t2454.scala deleted file mode 100644 index 00f2e6f67..000000000 --- a/tests/untried/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/untried/pos/t2464/JavaOne.java b/tests/untried/pos/t2464/JavaOne.java deleted file mode 100644 index ff36868a0..000000000 --- a/tests/untried/pos/t2464/JavaOne.java +++ /dev/null @@ -1,5 +0,0 @@ -class ClassTwo { - public static class Child { - public void func2() {return ;} - } -} diff --git a/tests/untried/pos/t2464/ScalaOne_1.scala b/tests/untried/pos/t2464/ScalaOne_1.scala deleted file mode 100644 index 1caf8ecae..000000000 --- a/tests/untried/pos/t2464/ScalaOne_1.scala +++ /dev/null @@ -1,6 +0,0 @@ -class ScalaClassOne extends ClassTwo.Child { - def func4() = { - func2 - } -} - diff --git a/tests/untried/pos/t2464/t2464_2.scala b/tests/untried/pos/t2464/t2464_2.scala deleted file mode 100644 index 13a52c952..000000000 --- a/tests/untried/pos/t2464/t2464_2.scala +++ /dev/null @@ -1,3 +0,0 @@ -object Test { - val c1 = new ScalaClassOne -} diff --git a/tests/untried/pos/t247.scala b/tests/untried/pos/t247.scala deleted file mode 100644 index fdcafeb2c..000000000 --- a/tests/untried/pos/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/untried/pos/t2484.scala b/tests/untried/pos/t2484.scala deleted file mode 100755 index 15165c247..000000000 --- a/tests/untried/pos/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/untried/pos/t2486.scala b/tests/untried/pos/t2486.scala deleted file mode 100644 index 69fe4c127..000000000 --- a/tests/untried/pos/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 => () } } -- cgit v1.2.3 From b2c545173ab4869eb1b193d44f822efb83df104c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 May 2014 18:14:20 +0200 Subject: Nothing is not a superclass of Null. Fix so it isn't. This caused an error in ErrorReporting because we do not propagate bounds into a type like ValOrDefDef[_]. Error in `ErrorReporting` is now fixed but the problem is reflected in test case `boundspropagation`. --- src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- src/dotty/tools/dotc/typer/ErrorReporting.scala | 6 +++++- tests/pending/pos/boundspropagation.scala | 26 +++++++++++++++++++++++++ tests/pos/typeinferNull.scala | 9 +++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/pending/pos/boundspropagation.scala create mode 100644 tests/pos/typeinferNull.scala (limited to 'tests/pos') diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index c7e7dc50d..498f912f9 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -418,7 +418,7 @@ object SymDenotations { /** Is this symbol a class that does not extend `AnyVal`? */ final def isNonValueClass(implicit ctx: Context): Boolean = - isClass && !derivesFrom(defn.AnyValClass) + isClass && !derivesFrom(defn.AnyValClass) && (symbol ne defn.NothingClass) /** Is this symbol a class references to which that are supertypes of null? */ final def isNullableClass(implicit ctx: Context): Boolean = diff --git a/src/dotty/tools/dotc/typer/ErrorReporting.scala b/src/dotty/tools/dotc/typer/ErrorReporting.scala index 8f9b01fe6..0b016769b 100644 --- a/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -28,7 +28,11 @@ object ErrorReporting { def errorMsg(msg: String, cx: Context): String = if (cx.mode is Mode.InferringReturnType) { cx.tree match { - case tree: Trees.ValOrDefDef[_] => + case tree: untpd.ValOrDefDef => + // Dotty deviation: Was Trees.ValOrDefDef[_], but this gives ValOrDefDef[Nothing] instead of + // ValOrDefDel[Null]. Scala handles it, but it looks accidental because bounds propagation + // fails if the parameter is invariant or cotravariant. + // See test pending/pos/boundspropagation.scala val treeSym = ctx.symOfContextTree(tree) if (treeSym.exists && treeSym.name == cycleSym.name && treeSym.owner == cycleSym.owner) { val result = if (cycleSym.isSourceMethod) " result" else "" diff --git a/tests/pending/pos/boundspropagation.scala b/tests/pending/pos/boundspropagation.scala new file mode 100644 index 000000000..560d5416c --- /dev/null +++ b/tests/pending/pos/boundspropagation.scala @@ -0,0 +1,26 @@ +// scalac fails for test2/3 +// dotc fails for all three +object test1 { + class Tree[-T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} +object test2 { + class Tree[T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} +object test3 { + class Tree[+T >: Null] + + + def f(x: Any): Tree[Null] = x match { + case y: Tree[_] => y + } +} diff --git a/tests/pos/typeinferNull.scala b/tests/pos/typeinferNull.scala new file mode 100644 index 000000000..ba25ae181 --- /dev/null +++ b/tests/pos/typeinferNull.scala @@ -0,0 +1,9 @@ +object typeinferNull { + + val x1 = null :: Nil + val x2 = List(null) + + var y1: List[Null] = x1 + y1 = x2 + +} -- cgit v1.2.3 From 394b645dd2d44ff68597527c6c690c73653f1bcb Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 9 May 2014 18:55:10 +0200 Subject: Fix of pos/t2429 This was a hard nut to crack. The problem exemplified by t2429 is that in a situation like val x: T = foo(...) where `foo` needs implicit parameters the expected result type `T` is propagated into the typechecking of foo(...) and consequently also into the implicit parameter search. This is often necessary, for instance to instantiate type parameters. But it can lead to overconstrained searches if in fact the right expansion is val x: T = viewToT(foo(...)(implicit params)) where `viewToT` is some implicit conversion. The fix handles that case by re-hecking the application foo(...) with an empty result type, if the implicit parameter search fails. But the re-checking is very subtle as is explained in the comment to `TyperState#tryWithFallback`. --- src/dotty/tools/dotc/config/Printers.scala | 2 +- src/dotty/tools/dotc/core/TyperState.scala | 54 ++++++++++++++++++++-- src/dotty/tools/dotc/reporting/StoreReporter.scala | 5 +- src/dotty/tools/dotc/transform/Erasure.scala | 4 +- src/dotty/tools/dotc/typer/Applications.scala | 2 +- src/dotty/tools/dotc/typer/Namer.scala | 12 ++++- src/dotty/tools/dotc/typer/ProtoTypes.scala | 9 ++-- src/dotty/tools/dotc/typer/Typer.scala | 53 ++++++++++++--------- tests/pending/pos/t2429.scala | 25 ---------- tests/pos/t2429.scala | 25 ++++++++++ 10 files changed, 130 insertions(+), 61 deletions(-) delete mode 100755 tests/pending/pos/t2429.scala create mode 100755 tests/pos/t2429.scala (limited to 'tests/pos') diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala index 680dee7ab..5bfe1d0b6 100644 --- a/src/dotty/tools/dotc/config/Printers.scala +++ b/src/dotty/tools/dotc/config/Printers.scala @@ -25,5 +25,5 @@ object Printers { val hk = noPrinter val incremental = noPrinter val config = noPrinter - val transforms = new Printer + val transforms = noPrinter } \ No newline at end of file diff --git a/src/dotty/tools/dotc/core/TyperState.scala b/src/dotty/tools/dotc/core/TyperState.scala index 59c934e0d..6a3ac4467 100644 --- a/src/dotty/tools/dotc/core/TyperState.scala +++ b/src/dotty/tools/dotc/core/TyperState.scala @@ -11,7 +11,10 @@ import printing.{Showable, Printer} import printing.Texts._ import collection.mutable -class TyperState(val reporter: Reporter) extends DotClass with Showable { +class TyperState(r: Reporter) extends DotClass with Showable { + + /** The current reporter */ + def reporter = r /** The current constraint set */ def constraint: Constraint = new Constraint(SimpleMap.Empty, SimpleMap.Empty) @@ -56,11 +59,17 @@ class TyperState(val reporter: Reporter) extends DotClass with Showable { /** Can this state be transitively committed until the top-level? */ def isGlobalCommittable: Boolean = false + def tryWithFallback[T](op: => T)(fallback: => T)(implicit ctx: Context): T = unsupported("tryWithFallBack") + override def toText(printer: Printer): Text = "ImmutableTyperState" } -class MutableTyperState(previous: TyperState, reporter: Reporter, override val isCommittable: Boolean) -extends TyperState(reporter) { +class MutableTyperState(previous: TyperState, r: Reporter, override val isCommittable: Boolean) +extends TyperState(r) { + + private var myReporter = r + + override def reporter = myReporter private var myConstraint: Constraint = previous.constraint @@ -112,5 +121,44 @@ extends TyperState(reporter) { constraint = constraint.remove(poly) } + /** Try operation `op`; if it produces errors, execute `fallback` with constraint and + * reporter as they were before `op` was executed. This is similar to `typer/tryEither`, + * but with one important difference: Any type variable instantiations produced by `op` + * are persisted even if `op` fails. This is normally not what one wants and therefore + * it is recommended to use + * + * tryEither { implicit ctx => op } { (_, _) => fallBack } + * + * instead of + * + * ctx.tryWithFallback(op)(fallBack) + * + * `tryWithFallback` is only used when an implicit parameter search fails + * and the whole expression is subsequently retype-checked with a Wildcard + * expected type (so as to allow an implicit conversion on the result and + * avoid over-constraining the implicit parameter search). In this case, + * the only type variables that might be falsely instantiated by `op` but + * not by `fallBack` are type variables in the typed expression itself, and + * these will be thrown away and new ones will be created on re-typing. + * So `tryWithFallback` is safe. It is also necessary because without it + * we do not propagate enough instantiation information into the implicit search + * and this might lead to a missing parameter type error. This is exhibited + * at several places in the test suite (for instance in `pos_typers`). + * Overall, this is rather ugly, but despite trying for 2 days I have not + * found a better solution. + */ + override def tryWithFallback[T](op: => T)(fallback: => T)(implicit ctx: Context): T = { + val savedReporter = myReporter + val savedConstraint = myConstraint + myReporter = new StoreReporter + val result = op + if (!reporter.hasErrors) result + else { + myReporter = savedReporter + myConstraint = savedConstraint + fallback + } + } + override def toText(printer: Printer): Text = constraint.toText(printer) } diff --git a/src/dotty/tools/dotc/reporting/StoreReporter.scala b/src/dotty/tools/dotc/reporting/StoreReporter.scala index ea8199102..2864c01f8 100644 --- a/src/dotty/tools/dotc/reporting/StoreReporter.scala +++ b/src/dotty/tools/dotc/reporting/StoreReporter.scala @@ -29,5 +29,8 @@ class StoreReporter extends Reporter { } override def flush()(implicit ctx: Context) = - if (infos != null) infos foreach ctx.reporter.report + if (infos != null) { + infos foreach ctx.reporter.report + infos = null + } } diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index e6d012d68..e56132057 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -349,7 +349,7 @@ object Erasure { tpd.DefDef(bridge, { paramss: List[List[tpd.Tree]] => val rhs = paramss.foldLeft(sel)((fun, vparams) => fun.tpe.widen match { - case MethodType(names, types) => Apply(fun, (vparams, types).zipped.map(adapt)) + case MethodType(names, types) => Apply(fun, (vparams, types).zipped.map(adapt(_, _, untpd.EmptyTree))) case a => error(s"can not resolve apply type $a") }) @@ -357,7 +357,7 @@ object Erasure { }) } - override def adapt(tree: Tree, pt: Type)(implicit ctx: Context): Tree = + override def adapt(tree: Tree, pt: Type, original: untpd.Tree)(implicit ctx: Context): Tree = ctx.traceIndented(i"adapting ${tree.showSummary}: ${tree.tpe} to $pt", show = true) { assert(ctx.phase == ctx.erasurePhase.next, ctx.phase) if (tree.isEmpty) tree else adaptToType(tree, pt) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 92acb7939..a4c26080d 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -346,7 +346,7 @@ trait Applications extends Compatibility { self: Typer => init() def addArg(arg: Tree, formal: Type): Unit = - typedArgBuf += adaptInterpolated(arg, formal.widenExpr) + typedArgBuf += adaptInterpolated(arg, formal.widenExpr, EmptyTree) def makeVarArg(n: Int, elemFormal: Type): Unit = { val args = typedArgBuf.takeRight(n).toList diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index c3f1dcc81..e9195a072 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -404,8 +404,18 @@ class Namer { typer: Typer => } } - final override def complete(denot: SymDenotation)(implicit ctx: Context) = + final override def complete(denot: SymDenotation)(implicit ctx: Context) = { + if (completions != noPrinter && ctx.typerState != this.ctx.typerState) { + completions.println(completions.getClass.toString) + def levels(c: Context): Int = + if (c.typerState eq this.ctx.typerState) 0 + else if (c.typerState == null) -1 + else if (c.outer.typerState == c.typerState) levels(c.outer) + else levels(c.outer) + 1 + completions.println(s"!!!completing ${denot.symbol.showLocated} in buried typerState, gap = ${levels(ctx)}") + } completeInCreationContext(denot) + } def completeInCreationContext(denot: SymDenotation): Unit = denot.info = typeSig(denot.symbol) diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 1438f9e16..a72e98418 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -204,7 +204,7 @@ object ProtoTypes { targ = typer.typedUnadapted(arg, formal) if (!ctx.reporter.hasPending) myTypedArg = myTypedArg.updated(arg, targ) } - typer.adapt(targ, formal) + typer.adapt(targ, formal, arg) } private var myTupled: Type = NoType @@ -236,7 +236,7 @@ object ProtoTypes { * * []: argType => resultType */ - abstract case class ViewProto(argType: Type, override val resultType: Type)(implicit ctx: Context) + abstract case class ViewProto(argType: Type, override val resultType: Type) extends CachedGroundType with ApplyingProto { def isMatchedBy(tp: Type)(implicit ctx: Context): Boolean = ctx.typer.isApplicable(tp, argType :: Nil, resultType) @@ -253,7 +253,7 @@ object ProtoTypes { override def deepenProto(implicit ctx: Context) = derivedViewProto(argType, resultType.deepenProto) } - class CachedViewProto(argType: Type, resultType: Type)(implicit ctx: Context) extends ViewProto(argType, resultType) { + class CachedViewProto(argType: Type, resultType: Type) extends ViewProto(argType, resultType) { override def computeHash = doHash(argType, resultType) } @@ -373,7 +373,8 @@ object ProtoTypes { case tp @ PolyParam(poly, pnum) => ctx.typerState.constraint.at(tp) match { case bounds: TypeBounds => wildApprox(WildcardType(bounds)) - case _ => WildcardType(wildApprox(poly.paramBounds(pnum)).bounds) + case NoType => WildcardType(wildApprox(poly.paramBounds(pnum)).bounds) + case inst => wildApprox(inst) } case MethodParam(mt, pnum) => WildcardType(TypeBounds.upper(wildApprox(mt.paramTypes(pnum)))) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 5d477193c..050fcbc76 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -954,7 +954,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") - try adapt(typedUnadapted(tree, pt), pt) + try adapt(typedUnadapted(tree, pt), pt, tree) catch { case ex: CyclicReference => errorTree(tree, cyclicErrorMsg(ex)) case ex: FatalTypeError => errorTree(tree, ex.getMessage) @@ -1036,7 +1036,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } val qualProto = SelectionProto(name, normalizedProto, NoViewsAllowed) tryEither { implicit ctx => - val qual1 = adaptInterpolated(qual, qualProto) + 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 @@ -1044,11 +1044,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case _ => tree }} - def adapt(tree: Tree, pt: Type)(implicit ctx: Context) = /*>|>*/ track("adapt") /*<|<*/ { + 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) /*<|<*/ { interpolateUndetVars(tree) tree overwriteType tree.tpe.simplified - adaptInterpolated(tree, pt) + adaptInterpolated(tree, pt, original) } } @@ -1090,7 +1090,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit * (14) When in mode EXPRmode, apply a view * If all this fails, error */ - def adaptInterpolated(tree: Tree, pt: Type)(implicit ctx: Context): Tree = { + def adaptInterpolated(tree: Tree, pt: Type, original: untpd.Tree)(implicit ctx: Context): Tree = { assert(pt.exists) @@ -1104,7 +1104,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def expectedStr = err.expectedTypeStr(pt) resolveOverloaded(alts, pt) match { case alt :: Nil => - adapt(tree.withType(alt), pt) + adapt(tree.withType(alt), pt, original) case Nil => def noMatches = errorTree(tree, @@ -1150,24 +1150,31 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def adaptNoArgs(wtp: Type): Tree = wtp match { case wtp: ExprType => - adaptInterpolated(tree.withType(wtp.resultType), pt) + adaptInterpolated(tree.withType(wtp.resultType), pt, original) case wtp: ImplicitMethodType if constrainResult(wtp, pt) => - def implicitArgError(msg: => String): Tree = { - ctx.error(msg, tree.pos.endPos) - EmptyTree - } - val args = (wtp.paramNames, wtp.paramTypes).zipped map { (pname, formal) => - def where = d"parameter $pname of $methodStr" - inferImplicit(formal, EmptyTree, tree.pos.endPos) match { - case SearchSuccess(arg, _, _) => - adapt(arg, formal) - case ambi: AmbiguousImplicits => - implicitArgError(s"ambiguous implicits: ${ambi.explanation} of $where") - case failure: SearchFailure => - implicitArgError(d"no implicit argument of type $formal found for $where" + failure.postscript) + def addImplicitArgs = { + def implicitArgError(msg: => String): Tree = { + ctx.error(msg, tree.pos.endPos) + EmptyTree + } + val args = (wtp.paramNames, wtp.paramTypes).zipped map { (pname, formal) => + def where = d"parameter $pname of $methodStr" + inferImplicit(formal, EmptyTree, tree.pos.endPos) match { + case SearchSuccess(arg, _, _) => + adapt(arg, formal) + case ambi: AmbiguousImplicits => + implicitArgError(s"ambiguous implicits: ${ambi.explanation} of $where") + case failure: SearchFailure => + implicitArgError(d"no implicit argument of type $formal found for $where" + failure.postscript) + } } + adapt(tpd.Apply(tree, args), pt) } - adapt(tpd.Apply(tree, args), pt) + if ((pt eq WildcardType) || original.isEmpty) addImplicitArgs + else + ctx.typerState.tryWithFallback(addImplicitArgs) { + adapt(typed(original, WildcardType), pt, EmptyTree) + } case wtp: MethodType if !pt.isInstanceOf[SingletonType] => val arity = if (defn.isFunctionType(pt)) defn.functionArity(pt) @@ -1176,7 +1183,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (arity >= 0 && !tree.symbol.isConstructor) typed(etaExpand(tree, wtp, arity), pt) else if (wtp.paramTypes.isEmpty) - adaptInterpolated(tpd.Apply(tree, Nil), pt) + adaptInterpolated(tpd.Apply(tree, Nil), pt, EmptyTree) else errorTree(tree, d"""missing arguments for $methodStr @@ -1235,7 +1242,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (pt.isInstanceOf[PolyProto]) tree else { val (_, tvars) = constrained(poly, tree) - adaptInterpolated(tree appliedToTypes tvars, pt) + adaptInterpolated(tree appliedToTypes tvars, pt, original) } case wtp => pt match { diff --git a/tests/pending/pos/t2429.scala b/tests/pending/pos/t2429.scala deleted file mode 100755 index 4cda3bde1..000000000 --- a/tests/pending/pos/t2429.scala +++ /dev/null @@ -1,25 +0,0 @@ -object Msg { - trait T - - trait TSeq - - object TSeq { - implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") - } - - def render: Unit = { - val msgs: TSeq = (List[(Any, Any)]().flatMap { - case (a, b) => { - a match { - case _ => b match { - case _ => sys.error("stub") - } - } - } - } /*: Seq[T] Adding this type annotation avoids the compile error.*/) - } -} -object Oops { - implicit def someImplicit(s: Seq[_]): String = sys.error("stub") - def item: String = Nil map { case e: Any => e } -} diff --git a/tests/pos/t2429.scala b/tests/pos/t2429.scala new file mode 100755 index 000000000..4cda3bde1 --- /dev/null +++ b/tests/pos/t2429.scala @@ -0,0 +1,25 @@ +object Msg { + trait T + + trait TSeq + + object TSeq { + implicit def fromSeq(s: Seq[T]): TSeq = sys.error("stub") + } + + def render: Unit = { + val msgs: TSeq = (List[(Any, Any)]().flatMap { + case (a, b) => { + a match { + case _ => b match { + case _ => sys.error("stub") + } + } + } + } /*: Seq[T] Adding this type annotation avoids the compile error.*/) + } +} +object Oops { + implicit def someImplicit(s: Seq[_]): String = sys.error("stub") + def item: String = Nil map { case e: Any => e } +} -- cgit v1.2.3 From c6d55bf67832b70052c07f2cb11a19d83a6739a0 Mon Sep 17 00:00:00 2001 From: Samuel Gruetter Date: Wed, 14 May 2014 13:58:04 +0200 Subject: remove test t1591b because it depends on scalac 2 source --- tests/pos/t1591b.scala | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/pos/t1591b.scala (limited to 'tests/pos') diff --git a/tests/pos/t1591b.scala b/tests/pos/t1591b.scala deleted file mode 100644 index c671ad647..000000000 --- a/tests/pos/t1591b.scala +++ /dev/null @@ -1,13 +0,0 @@ -import scala.tools.nsc._ - -class SemanticTokens(val compiler: Global) { - import compiler._ - - def build() = ErrorType - - class Process { - def f() = analyzer - // or to crash the compiler instead of a nice message, - // def f() = analyzer underlying _ - } -} -- cgit v1.2.3