From f5972c7904ce802e3e7668094726c21c3a603419 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 15:43:43 +0200 Subject: [PATCH 01/17] Fix testing in tree checker. Tree checker typed always dropped the expected type and replaced it by a wildcard. This meant that type checking dor -Ycheck was much weaker than it should be. A class of GADT problems is only diagnosed once the expected type is proberly propagated. --- src/dotty/tools/dotc/transform/TreeChecker.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index ce160d7b0550..18e3a6c8aa5d 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -258,7 +258,7 @@ class TreeChecker extends Phase with SymTransformer { } override def typed(tree: untpd.Tree, pt: Type = WildcardType)(implicit ctx: Context): tpd.Tree = { - val tpdTree = super.typed(tree) + val tpdTree = super.typed(tree, pt) checkIdentNotJavaClass(tpdTree) tpdTree } From 23d1bfb4111d8aff513659f2b3e3dd695b9b6e03 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 15:46:06 +0200 Subject: [PATCH 02/17] Make expressions using GADTs type check in later phases GADT logic is lost after PatMat. To make code typecheck, the typer should already insert casts where a subtype check succeeded because it involved bounds established by a GADT comparison. --- src/dotty/tools/dotc/core/TypeComparer.scala | 19 +++++++++++++++++-- src/dotty/tools/dotc/typer/Typer.scala | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index 8d7e9d1641cc..e9300c0ba2c0 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -76,6 +76,19 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { myNothingType } + /** Indicates whether a previous subtype check used GADT bounds */ + var GADTused = false + + /** Record that GADT bounds of `sym` were used in a subtype check. + * But exclude constructor type parameters, as these are aliased + * to the corresponding class parameters, which does not constitute + * a true usage of a GADT symbol. + */ + private def GADTusage(sym: Symbol) = { + if (!sym.owner.isConstructor) GADTused = true + true + } + // Subtype testing `<:<` def topLevelSubType(tp1: Type, tp2: Type): Boolean = { @@ -325,7 +338,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { val gbounds2 = ctx.gadt.bounds(tp2.symbol) (gbounds2 != null) && (isSubTypeWhenFrozen(tp1, gbounds2.lo) || - narrowGADTBounds(tp2, tp1, isUpper = false)) + narrowGADTBounds(tp2, tp1, isUpper = false)) && + GADTusage(tp2.symbol) } ((frozenConstraint || !isCappable(tp1)) && isSubType(tp1, lo2) || compareGADT || @@ -507,7 +521,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { val gbounds1 = ctx.gadt.bounds(tp1.symbol) (gbounds1 != null) && (isSubTypeWhenFrozen(gbounds1.hi, tp2) || - narrowGADTBounds(tp1, tp2, isUpper = true)) + narrowGADTBounds(tp1, tp2, isUpper = true)) && + GADTusage(tp1.symbol) } isSubType(hi1, tp2) || compareGADT case _ => diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 7eb022b514f9..39d9d267eb6a 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1715,6 +1715,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit else missingArgs case _ => + ctx.typeComparer.GADTused = false if (ctx.mode is Mode.Pattern) { tree match { case _: RefTree | _: Literal if !isVarPattern(tree) => @@ -1723,7 +1724,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } tree } - else if (tree.tpe <:< pt) tree + else if (tree.tpe <:< pt) + if (ctx.typeComparer.GADTused) tree.asInstance(pt) + else tree else if (wtp.isInstanceOf[MethodType]) missingArgs else { typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt") From 8f5bd779903d5c9f29bc3750391ffacbf3cf869e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 16:16:06 +0200 Subject: [PATCH 03/17] GADT test This one failed in getters before because a (previously unchecked) assignment was turned into a checked application. Now it passes. --- tests/{pending => }/pos/gadts2.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{pending => }/pos/gadts2.scala (74%) diff --git a/tests/pending/pos/gadts2.scala b/tests/pos/gadts2.scala similarity index 74% rename from tests/pending/pos/gadts2.scala rename to tests/pos/gadts2.scala index b67bafb32638..71089c0f7872 100644 --- a/tests/pending/pos/gadts2.scala +++ b/tests/pos/gadts2.scala @@ -8,9 +8,9 @@ object Test { case class Cell[a](var x: a) extends Term[a] final case class NumTerm(val n: Number) extends Term[Number] - def f[a](t: Term[a], c: Cell[a]): Unit = { + def f[A](t: Term[A], c: Cell[A]): Unit = { t match { - case NumTerm(n) => c.x = MyDouble(1.0) + case NumTerm(n) => c.x = MyDouble(1.0) // problem is: this assignment is not type correct, since gadt variable is forgotten } } From d84805299a42cb8d2c756aff5a117af24dbeaaf4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 16:18:49 +0200 Subject: [PATCH 04/17] Recategorize tests Passing tests from pending/pos go in pos. Some others go in diabled/not-testable. These are tests that require a compilation order which we cannot yet do with our unit testing framework. Compiling them alltogether (as is now doen in junit) does not work either for them because they contain a duplicate class. --- test/dotc/tests.scala | 1 + .../not-representable}/t3999b.scala | 0 .../not-testable}/t5604b/T_1.scala | 0 .../not-testable}/t5604b/T_2.scala | 0 .../not-testable}/t5604b/Test_1.scala | 0 .../not-testable}/t5604b/Test_2.scala | 0 .../not-testable}/t5604b/pack_1.scala | 0 .../not-testable}/t8134/A_1.scala | 0 .../not-testable}/t8134/B_2.scala | 0 tests/pending/pos/contraImplicits.scala | 18 ------------------ tests/pending/pos/depsel.scala | 14 -------------- tests/pending/pos/exponential-spec.scala | 4 ++-- tests/pending/pos/generic-sigs.flags | 1 - tests/pending/pos/setter-not-implicit.scala | 3 --- tests/pending/pos/stable.scala | 11 ----------- tests/pending/pos/t3631.scala | 1 + tests/pending/pos/t3960.flags | 1 - tests/pending/pos/t4188.scala | 1 + tests/pending/pos/t4579.flags | 1 - tests/pending/pos/t4911.flags | 1 - tests/pending/pos/t5029.flags | 1 - tests/pending/pos/t5899.flags | 1 - tests/pending/pos/t5932.flags | 1 - tests/pending/pos/t5954a/A_1.scala | 6 ------ tests/pending/pos/t5954a/B_2.scala | 6 ------ tests/pending/pos/t5954b/A_1.scala | 6 ------ tests/pending/pos/t5954b/B_2.scala | 5 ----- tests/pending/pos/t5954c/A_1.scala | 18 ------------------ tests/pending/pos/t5954c/B_2.scala | 18 ------------------ tests/pending/pos/t5954d/A_1.scala | 6 ------ tests/pending/pos/t5954d/B_2.scala | 7 ------- .../pos/t6123-explaintypes-implicits.flags | 1 - tests/pending/pos/t6994.flags | 1 - tests/pending/pos/t7011.flags | 1 - tests/pending/pos/t7285a.flags | 1 - tests/pending/pos/t7296.scala | 1 + tests/pending/pos/t8187.check | 0 tests/pending/pos/t8364.check | 0 tests/pending/pos/t8369a.check | 0 tests/pending/pos/virtpatmat_alts_subst.flags | 1 - tests/pending/pos/virtpatmat_exist1.flags | 1 - tests/pending/pos/virtpatmat_exist3.flags | 1 - .../{pending/pos => pos-special}/t8146a.scala | 0 tests/{pending => }/pos/apply-equiv.scala | 0 tests/{pending => }/pos/extractor-types.scala | 0 tests/{pending => }/pos/hk-infer.scala | 0 tests/{pending => }/pos/i743.scala | 0 tests/{pending => }/pos/infersingle.scala | 0 tests/{pending => }/pos/lazyvals.scala | 0 tests/{pending => }/pos/matthias4.scala | 0 tests/{pending => }/pos/mixins.scala | 0 tests/{pending => }/pos/return_thistype.scala | 0 tests/{pending => }/pos/t3494.scala | 0 tests/{pending => }/pos/t3800.scala | 0 tests/{pending => }/pos/t3862.scala | 0 tests/{pending => }/pos/t3880.scala | 0 tests/{pending => }/pos/t3999/a_1.scala | 2 +- tests/{pending => }/pos/t3999/b_2.scala | 0 tests/{pending => }/pos/t4269.scala | 0 tests/{pending => }/pos/t5330.scala | 0 tests/{pending => }/pos/t5604/ReplConfig.scala | 0 .../{pending => }/pos/t5604/ReplReporter.scala | 0 tests/{pending => }/pos/t5726.scala | 0 tests/{pending => }/pos/t5769.scala | 0 tests/{pending => }/pos/t578.scala | 0 tests/{pending => }/pos/t5899.scala | 0 tests/{pending => }/pos/t6084.scala | 0 tests/{pending => }/pos/t6722.scala | 0 tests/{pending => }/pos/t6815_import.scala | 0 tests/{pending => }/pos/t6948.scala | 0 tests/{pending => }/pos/t7517.scala | 0 tests/{pending => }/pos/t7902.scala | 0 tests/{pending => }/pos/t8046c.scala | 0 tests/{pending => }/pos/t807.scala | 0 tests/{pending => }/pos/t8300-patmat-a.scala | 0 tests/{pending => }/pos/t8300-patmat-b.scala | 0 tests/{pending => }/pos/t8301b.scala | 0 tests/{pending => }/pos/t8364.scala | 0 tests/{pending => }/pos/trait-force-info.scala | 0 79 files changed, 7 insertions(+), 135 deletions(-) rename tests/{pending/pos => disabled/not-representable}/t3999b.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t5604b/T_1.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t5604b/T_2.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t5604b/Test_1.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t5604b/Test_2.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t5604b/pack_1.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t8134/A_1.scala (100%) rename tests/{pending/pos => disabled/not-testable}/t8134/B_2.scala (100%) delete mode 100644 tests/pending/pos/contraImplicits.scala delete mode 100644 tests/pending/pos/depsel.scala delete mode 100644 tests/pending/pos/generic-sigs.flags delete mode 100644 tests/pending/pos/setter-not-implicit.scala delete mode 100644 tests/pending/pos/stable.scala delete mode 100644 tests/pending/pos/t3960.flags delete mode 100644 tests/pending/pos/t4579.flags delete mode 100644 tests/pending/pos/t4911.flags delete mode 100644 tests/pending/pos/t5029.flags delete mode 100644 tests/pending/pos/t5899.flags delete mode 100644 tests/pending/pos/t5932.flags delete mode 100644 tests/pending/pos/t5954a/A_1.scala delete mode 100644 tests/pending/pos/t5954a/B_2.scala delete mode 100644 tests/pending/pos/t5954b/A_1.scala delete mode 100644 tests/pending/pos/t5954b/B_2.scala delete mode 100644 tests/pending/pos/t5954c/A_1.scala delete mode 100644 tests/pending/pos/t5954c/B_2.scala delete mode 100644 tests/pending/pos/t5954d/A_1.scala delete mode 100644 tests/pending/pos/t5954d/B_2.scala delete mode 100644 tests/pending/pos/t6123-explaintypes-implicits.flags delete mode 100644 tests/pending/pos/t6994.flags delete mode 100644 tests/pending/pos/t7011.flags delete mode 100644 tests/pending/pos/t7285a.flags delete mode 100644 tests/pending/pos/t8187.check delete mode 100644 tests/pending/pos/t8364.check delete mode 100644 tests/pending/pos/t8369a.check delete mode 100644 tests/pending/pos/virtpatmat_alts_subst.flags delete mode 100644 tests/pending/pos/virtpatmat_exist1.flags delete mode 100644 tests/pending/pos/virtpatmat_exist3.flags rename tests/{pending/pos => pos-special}/t8146a.scala (100%) rename tests/{pending => }/pos/apply-equiv.scala (100%) rename tests/{pending => }/pos/extractor-types.scala (100%) rename tests/{pending => }/pos/hk-infer.scala (100%) rename tests/{pending => }/pos/i743.scala (100%) rename tests/{pending => }/pos/infersingle.scala (100%) rename tests/{pending => }/pos/lazyvals.scala (100%) rename tests/{pending => }/pos/matthias4.scala (100%) rename tests/{pending => }/pos/mixins.scala (100%) rename tests/{pending => }/pos/return_thistype.scala (100%) rename tests/{pending => }/pos/t3494.scala (100%) rename tests/{pending => }/pos/t3800.scala (100%) rename tests/{pending => }/pos/t3862.scala (100%) rename tests/{pending => }/pos/t3880.scala (100%) rename tests/{pending => }/pos/t3999/a_1.scala (65%) rename tests/{pending => }/pos/t3999/b_2.scala (100%) rename tests/{pending => }/pos/t4269.scala (100%) rename tests/{pending => }/pos/t5330.scala (100%) rename tests/{pending => }/pos/t5604/ReplConfig.scala (100%) rename tests/{pending => }/pos/t5604/ReplReporter.scala (100%) rename tests/{pending => }/pos/t5726.scala (100%) rename tests/{pending => }/pos/t5769.scala (100%) rename tests/{pending => }/pos/t578.scala (100%) rename tests/{pending => }/pos/t5899.scala (100%) rename tests/{pending => }/pos/t6084.scala (100%) rename tests/{pending => }/pos/t6722.scala (100%) rename tests/{pending => }/pos/t6815_import.scala (100%) rename tests/{pending => }/pos/t6948.scala (100%) rename tests/{pending => }/pos/t7517.scala (100%) rename tests/{pending => }/pos/t7902.scala (100%) rename tests/{pending => }/pos/t8046c.scala (100%) rename tests/{pending => }/pos/t807.scala (100%) rename tests/{pending => }/pos/t8300-patmat-a.scala (100%) rename tests/{pending => }/pos/t8300-patmat-b.scala (100%) rename tests/{pending => }/pos/t8301b.scala (100%) rename tests/{pending => }/pos/t8364.scala (100%) rename tests/{pending => }/pos/trait-force-info.scala (100%) diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 31e74fa97cf8..9f95a30c17c3 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -110,6 +110,7 @@ class tests extends CompilerTest { @Test def rewrites = compileFile(posScala2Dir, "rewrites", "-rewrite" :: scala2mode) @Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes) + @Test def pos_t8146a = compileFile(posSpecialDir, "t8146a")(allowDeepSubtypes) @Test def pos_t5545 = { // compile by hand in two batches, since junit lacks the infrastructure to diff --git a/tests/pending/pos/t3999b.scala b/tests/disabled/not-representable/t3999b.scala similarity index 100% rename from tests/pending/pos/t3999b.scala rename to tests/disabled/not-representable/t3999b.scala diff --git a/tests/pending/pos/t5604b/T_1.scala b/tests/disabled/not-testable/t5604b/T_1.scala similarity index 100% rename from tests/pending/pos/t5604b/T_1.scala rename to tests/disabled/not-testable/t5604b/T_1.scala diff --git a/tests/pending/pos/t5604b/T_2.scala b/tests/disabled/not-testable/t5604b/T_2.scala similarity index 100% rename from tests/pending/pos/t5604b/T_2.scala rename to tests/disabled/not-testable/t5604b/T_2.scala diff --git a/tests/pending/pos/t5604b/Test_1.scala b/tests/disabled/not-testable/t5604b/Test_1.scala similarity index 100% rename from tests/pending/pos/t5604b/Test_1.scala rename to tests/disabled/not-testable/t5604b/Test_1.scala diff --git a/tests/pending/pos/t5604b/Test_2.scala b/tests/disabled/not-testable/t5604b/Test_2.scala similarity index 100% rename from tests/pending/pos/t5604b/Test_2.scala rename to tests/disabled/not-testable/t5604b/Test_2.scala diff --git a/tests/pending/pos/t5604b/pack_1.scala b/tests/disabled/not-testable/t5604b/pack_1.scala similarity index 100% rename from tests/pending/pos/t5604b/pack_1.scala rename to tests/disabled/not-testable/t5604b/pack_1.scala diff --git a/tests/pending/pos/t8134/A_1.scala b/tests/disabled/not-testable/t8134/A_1.scala similarity index 100% rename from tests/pending/pos/t8134/A_1.scala rename to tests/disabled/not-testable/t8134/A_1.scala diff --git a/tests/pending/pos/t8134/B_2.scala b/tests/disabled/not-testable/t8134/B_2.scala similarity index 100% rename from tests/pending/pos/t8134/B_2.scala rename to tests/disabled/not-testable/t8134/B_2.scala diff --git a/tests/pending/pos/contraImplicits.scala b/tests/pending/pos/contraImplicits.scala deleted file mode 100644 index c4d6596158b3..000000000000 --- a/tests/pending/pos/contraImplicits.scala +++ /dev/null @@ -1,18 +0,0 @@ -import scala.reflect._ -// this needs to be fleshed out further -class Contra[-T] - -object Test { - def getParam[T](c: Contra[T])(implicit ct: ClassTag[T]): Unit = { - println(ct) - ct - } - def f[T](x: Contra[T]): Contra[T] = x - - def main(args: Array[String]): Unit = { - val x = f(new Contra[Int]) - val y: Contra[Int] = x - getParam(new Contra[Int]) - } -} - diff --git a/tests/pending/pos/depsel.scala b/tests/pending/pos/depsel.scala deleted file mode 100644 index 2cec4349e18d..000000000000 --- a/tests/pending/pos/depsel.scala +++ /dev/null @@ -1,14 +0,0 @@ -// demonstrates selection on non-path types. Needs to be fleshed out to -// become a real test. -object Test { - - class C { - type T - val f: T => T = ??? - } - - var x = new C - val y = x.f - - -} diff --git a/tests/pending/pos/exponential-spec.scala b/tests/pending/pos/exponential-spec.scala index 54515c1d21d5..26c9ab85e7f0 100644 --- a/tests/pending/pos/exponential-spec.scala +++ b/tests/pending/pos/exponential-spec.scala @@ -23,7 +23,7 @@ object Test { compose f[T] // 8s compose f[T] // 11s compose f[T] // 17s - compose f[T] // 29s +/* compose f[T] // 29s compose f[T] // 54s compose f[T] compose f[T] @@ -42,6 +42,6 @@ object Test { compose f[T] compose f[T] compose f[T] - compose f[T] + compose f[T]*/ )(exp) } diff --git a/tests/pending/pos/generic-sigs.flags b/tests/pending/pos/generic-sigs.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/generic-sigs.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/setter-not-implicit.scala b/tests/pending/pos/setter-not-implicit.scala deleted file mode 100644 index 9bfffc2ceb3e..000000000000 --- a/tests/pending/pos/setter-not-implicit.scala +++ /dev/null @@ -1,3 +0,0 @@ -object O { - implicit var x: Int = 0 -} diff --git a/tests/pending/pos/stable.scala b/tests/pending/pos/stable.scala deleted file mode 100644 index 267a36fe5cad..000000000000 --- a/tests/pending/pos/stable.scala +++ /dev/null @@ -1,11 +0,0 @@ -trait Base { - val x: Int; - val y: Int; - var z: Int; -} - -class Sub() extends Base { - val x: Int = 1; - val y: Int = 2; - var z: Int = 3; -} diff --git a/tests/pending/pos/t3631.scala b/tests/pending/pos/t3631.scala index e723741307ed..207e28cd76c3 100644 --- a/tests/pending/pos/t3631.scala +++ b/tests/pending/pos/t3631.scala @@ -1,3 +1,4 @@ +// fails Ycheck case class X22(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) { } case class X23(x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int, x23: Int) { } diff --git a/tests/pending/pos/t3960.flags b/tests/pending/pos/t3960.flags deleted file mode 100644 index 4449dbbdf333..000000000000 --- a/tests/pending/pos/t3960.flags +++ /dev/null @@ -1 +0,0 @@ --Ycheck:typer \ No newline at end of file diff --git a/tests/pending/pos/t4188.scala b/tests/pending/pos/t4188.scala index 40e7d4924e36..104473fc51b2 100644 --- a/tests/pending/pos/t4188.scala +++ b/tests/pending/pos/t4188.scala @@ -1,3 +1,4 @@ +// Fails Ycheck class A { object Ding class B { diff --git a/tests/pending/pos/t4579.flags b/tests/pending/pos/t4579.flags deleted file mode 100644 index 1182725e8633..000000000000 --- a/tests/pending/pos/t4579.flags +++ /dev/null @@ -1 +0,0 @@ --optimize \ No newline at end of file diff --git a/tests/pending/pos/t4911.flags b/tests/pending/pos/t4911.flags deleted file mode 100644 index 779916d58f80..000000000000 --- a/tests/pending/pos/t4911.flags +++ /dev/null @@ -1 +0,0 @@ --unchecked -Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t5029.flags b/tests/pending/pos/t5029.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/t5029.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t5899.flags b/tests/pending/pos/t5899.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/t5899.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t5932.flags b/tests/pending/pos/t5932.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/t5932.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t5954a/A_1.scala b/tests/pending/pos/t5954a/A_1.scala deleted file mode 100644 index 10ead0b1ca09..000000000000 --- a/tests/pending/pos/t5954a/A_1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package p1 { - object `package` { - implicit class Foo(a: Any) - object Foo - } -} diff --git a/tests/pending/pos/t5954a/B_2.scala b/tests/pending/pos/t5954a/B_2.scala deleted file mode 100644 index 10ead0b1ca09..000000000000 --- a/tests/pending/pos/t5954a/B_2.scala +++ /dev/null @@ -1,6 +0,0 @@ -package p1 { - object `package` { - implicit class Foo(a: Any) - object Foo - } -} diff --git a/tests/pending/pos/t5954b/A_1.scala b/tests/pending/pos/t5954b/A_1.scala deleted file mode 100644 index 8465e8f8c6ce..000000000000 --- a/tests/pending/pos/t5954b/A_1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package p { - package object base { - class B - object B - } -} diff --git a/tests/pending/pos/t5954b/B_2.scala b/tests/pending/pos/t5954b/B_2.scala deleted file mode 100644 index f7e4704b3e62..000000000000 --- a/tests/pending/pos/t5954b/B_2.scala +++ /dev/null @@ -1,5 +0,0 @@ -package p { - package object base { - case class B() - } -} diff --git a/tests/pending/pos/t5954c/A_1.scala b/tests/pending/pos/t5954c/A_1.scala deleted file mode 100644 index 29ad9547a232..000000000000 --- a/tests/pending/pos/t5954c/A_1.scala +++ /dev/null @@ -1,18 +0,0 @@ -package object A { - // these used to should be prevented by the implementation restriction - // but are now allowed - class B - object B - trait C - object C - case class D() - // all the rest of these should be ok - class E - object F - val g = "omg" - var h = "wtf" - def i = "lol" - type j = String - class K(val k : Int) extends AnyVal - implicit class L(val l : Int) -} diff --git a/tests/pending/pos/t5954c/B_2.scala b/tests/pending/pos/t5954c/B_2.scala deleted file mode 100644 index 29ad9547a232..000000000000 --- a/tests/pending/pos/t5954c/B_2.scala +++ /dev/null @@ -1,18 +0,0 @@ -package object A { - // these used to should be prevented by the implementation restriction - // but are now allowed - class B - object B - trait C - object C - case class D() - // all the rest of these should be ok - class E - object F - val g = "omg" - var h = "wtf" - def i = "lol" - type j = String - class K(val k : Int) extends AnyVal - implicit class L(val l : Int) -} diff --git a/tests/pending/pos/t5954d/A_1.scala b/tests/pending/pos/t5954d/A_1.scala deleted file mode 100644 index 8465e8f8c6ce..000000000000 --- a/tests/pending/pos/t5954d/A_1.scala +++ /dev/null @@ -1,6 +0,0 @@ -package p { - package object base { - class B - object B - } -} diff --git a/tests/pending/pos/t5954d/B_2.scala b/tests/pending/pos/t5954d/B_2.scala deleted file mode 100644 index a4aa2eb587e1..000000000000 --- a/tests/pending/pos/t5954d/B_2.scala +++ /dev/null @@ -1,7 +0,0 @@ -package p { - trait T { - class B - object B - } - package object base extends T -} diff --git a/tests/pending/pos/t6123-explaintypes-implicits.flags b/tests/pending/pos/t6123-explaintypes-implicits.flags deleted file mode 100644 index b36707c7cfcf..000000000000 --- a/tests/pending/pos/t6123-explaintypes-implicits.flags +++ /dev/null @@ -1 +0,0 @@ --explaintypes diff --git a/tests/pending/pos/t6994.flags b/tests/pending/pos/t6994.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/t6994.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t7011.flags b/tests/pending/pos/t7011.flags deleted file mode 100644 index a4c161553eea..000000000000 --- a/tests/pending/pos/t7011.flags +++ /dev/null @@ -1 +0,0 @@ --Ydebug -Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t7285a.flags b/tests/pending/pos/t7285a.flags deleted file mode 100644 index e8fb65d50c20..000000000000 --- a/tests/pending/pos/t7285a.flags +++ /dev/null @@ -1 +0,0 @@ --Xfatal-warnings \ No newline at end of file diff --git a/tests/pending/pos/t7296.scala b/tests/pending/pos/t7296.scala index 0c078d3657b3..fcba17c0845e 100644 --- a/tests/pending/pos/t7296.scala +++ b/tests/pending/pos/t7296.scala @@ -1,3 +1,4 @@ +// Fails Ycheck object Test { type A = Int // Emits the implementation restriction but then proceeds to crash diff --git a/tests/pending/pos/t8187.check b/tests/pending/pos/t8187.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/pending/pos/t8364.check b/tests/pending/pos/t8364.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/pending/pos/t8369a.check b/tests/pending/pos/t8369a.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/pending/pos/virtpatmat_alts_subst.flags b/tests/pending/pos/virtpatmat_alts_subst.flags deleted file mode 100644 index 3f5a3100e469..000000000000 --- a/tests/pending/pos/virtpatmat_alts_subst.flags +++ /dev/null @@ -1 +0,0 @@ - -Xexperimental diff --git a/tests/pending/pos/virtpatmat_exist1.flags b/tests/pending/pos/virtpatmat_exist1.flags deleted file mode 100644 index 3f5a3100e469..000000000000 --- a/tests/pending/pos/virtpatmat_exist1.flags +++ /dev/null @@ -1 +0,0 @@ - -Xexperimental diff --git a/tests/pending/pos/virtpatmat_exist3.flags b/tests/pending/pos/virtpatmat_exist3.flags deleted file mode 100644 index 3f5a3100e469..000000000000 --- a/tests/pending/pos/virtpatmat_exist3.flags +++ /dev/null @@ -1 +0,0 @@ - -Xexperimental diff --git a/tests/pending/pos/t8146a.scala b/tests/pos-special/t8146a.scala similarity index 100% rename from tests/pending/pos/t8146a.scala rename to tests/pos-special/t8146a.scala diff --git a/tests/pending/pos/apply-equiv.scala b/tests/pos/apply-equiv.scala similarity index 100% rename from tests/pending/pos/apply-equiv.scala rename to tests/pos/apply-equiv.scala diff --git a/tests/pending/pos/extractor-types.scala b/tests/pos/extractor-types.scala similarity index 100% rename from tests/pending/pos/extractor-types.scala rename to tests/pos/extractor-types.scala diff --git a/tests/pending/pos/hk-infer.scala b/tests/pos/hk-infer.scala similarity index 100% rename from tests/pending/pos/hk-infer.scala rename to tests/pos/hk-infer.scala diff --git a/tests/pending/pos/i743.scala b/tests/pos/i743.scala similarity index 100% rename from tests/pending/pos/i743.scala rename to tests/pos/i743.scala diff --git a/tests/pending/pos/infersingle.scala b/tests/pos/infersingle.scala similarity index 100% rename from tests/pending/pos/infersingle.scala rename to tests/pos/infersingle.scala diff --git a/tests/pending/pos/lazyvals.scala b/tests/pos/lazyvals.scala similarity index 100% rename from tests/pending/pos/lazyvals.scala rename to tests/pos/lazyvals.scala diff --git a/tests/pending/pos/matthias4.scala b/tests/pos/matthias4.scala similarity index 100% rename from tests/pending/pos/matthias4.scala rename to tests/pos/matthias4.scala diff --git a/tests/pending/pos/mixins.scala b/tests/pos/mixins.scala similarity index 100% rename from tests/pending/pos/mixins.scala rename to tests/pos/mixins.scala diff --git a/tests/pending/pos/return_thistype.scala b/tests/pos/return_thistype.scala similarity index 100% rename from tests/pending/pos/return_thistype.scala rename to tests/pos/return_thistype.scala diff --git a/tests/pending/pos/t3494.scala b/tests/pos/t3494.scala similarity index 100% rename from tests/pending/pos/t3494.scala rename to tests/pos/t3494.scala diff --git a/tests/pending/pos/t3800.scala b/tests/pos/t3800.scala similarity index 100% rename from tests/pending/pos/t3800.scala rename to tests/pos/t3800.scala diff --git a/tests/pending/pos/t3862.scala b/tests/pos/t3862.scala similarity index 100% rename from tests/pending/pos/t3862.scala rename to tests/pos/t3862.scala diff --git a/tests/pending/pos/t3880.scala b/tests/pos/t3880.scala similarity index 100% rename from tests/pending/pos/t3880.scala rename to tests/pos/t3880.scala diff --git a/tests/pending/pos/t3999/a_1.scala b/tests/pos/t3999/a_1.scala similarity index 65% rename from tests/pending/pos/t3999/a_1.scala rename to tests/pos/t3999/a_1.scala index be9cc371e9dc..7ef67bba4684 100644 --- a/tests/pending/pos/t3999/a_1.scala +++ b/tests/pos/t3999/a_1.scala @@ -4,6 +4,6 @@ class Outside package object bar { class Val(b: Boolean) - implicit def boolean2Val(b: Boolean): foo.bar.package.Val = new Val(b) + implicit def boolean2Val(b: Boolean): foo.bar.`package`.Val = new Val(b) implicit def boolean2Outside(b: Boolean): foo.Outside = new Outside } diff --git a/tests/pending/pos/t3999/b_2.scala b/tests/pos/t3999/b_2.scala similarity index 100% rename from tests/pending/pos/t3999/b_2.scala rename to tests/pos/t3999/b_2.scala diff --git a/tests/pending/pos/t4269.scala b/tests/pos/t4269.scala similarity index 100% rename from tests/pending/pos/t4269.scala rename to tests/pos/t4269.scala diff --git a/tests/pending/pos/t5330.scala b/tests/pos/t5330.scala similarity index 100% rename from tests/pending/pos/t5330.scala rename to tests/pos/t5330.scala diff --git a/tests/pending/pos/t5604/ReplConfig.scala b/tests/pos/t5604/ReplConfig.scala similarity index 100% rename from tests/pending/pos/t5604/ReplConfig.scala rename to tests/pos/t5604/ReplConfig.scala diff --git a/tests/pending/pos/t5604/ReplReporter.scala b/tests/pos/t5604/ReplReporter.scala similarity index 100% rename from tests/pending/pos/t5604/ReplReporter.scala rename to tests/pos/t5604/ReplReporter.scala diff --git a/tests/pending/pos/t5726.scala b/tests/pos/t5726.scala similarity index 100% rename from tests/pending/pos/t5726.scala rename to tests/pos/t5726.scala diff --git a/tests/pending/pos/t5769.scala b/tests/pos/t5769.scala similarity index 100% rename from tests/pending/pos/t5769.scala rename to tests/pos/t5769.scala diff --git a/tests/pending/pos/t578.scala b/tests/pos/t578.scala similarity index 100% rename from tests/pending/pos/t578.scala rename to tests/pos/t578.scala diff --git a/tests/pending/pos/t5899.scala b/tests/pos/t5899.scala similarity index 100% rename from tests/pending/pos/t5899.scala rename to tests/pos/t5899.scala diff --git a/tests/pending/pos/t6084.scala b/tests/pos/t6084.scala similarity index 100% rename from tests/pending/pos/t6084.scala rename to tests/pos/t6084.scala diff --git a/tests/pending/pos/t6722.scala b/tests/pos/t6722.scala similarity index 100% rename from tests/pending/pos/t6722.scala rename to tests/pos/t6722.scala diff --git a/tests/pending/pos/t6815_import.scala b/tests/pos/t6815_import.scala similarity index 100% rename from tests/pending/pos/t6815_import.scala rename to tests/pos/t6815_import.scala diff --git a/tests/pending/pos/t6948.scala b/tests/pos/t6948.scala similarity index 100% rename from tests/pending/pos/t6948.scala rename to tests/pos/t6948.scala diff --git a/tests/pending/pos/t7517.scala b/tests/pos/t7517.scala similarity index 100% rename from tests/pending/pos/t7517.scala rename to tests/pos/t7517.scala diff --git a/tests/pending/pos/t7902.scala b/tests/pos/t7902.scala similarity index 100% rename from tests/pending/pos/t7902.scala rename to tests/pos/t7902.scala diff --git a/tests/pending/pos/t8046c.scala b/tests/pos/t8046c.scala similarity index 100% rename from tests/pending/pos/t8046c.scala rename to tests/pos/t8046c.scala diff --git a/tests/pending/pos/t807.scala b/tests/pos/t807.scala similarity index 100% rename from tests/pending/pos/t807.scala rename to tests/pos/t807.scala diff --git a/tests/pending/pos/t8300-patmat-a.scala b/tests/pos/t8300-patmat-a.scala similarity index 100% rename from tests/pending/pos/t8300-patmat-a.scala rename to tests/pos/t8300-patmat-a.scala diff --git a/tests/pending/pos/t8300-patmat-b.scala b/tests/pos/t8300-patmat-b.scala similarity index 100% rename from tests/pending/pos/t8300-patmat-b.scala rename to tests/pos/t8300-patmat-b.scala diff --git a/tests/pending/pos/t8301b.scala b/tests/pos/t8301b.scala similarity index 100% rename from tests/pending/pos/t8301b.scala rename to tests/pos/t8301b.scala diff --git a/tests/pending/pos/t8364.scala b/tests/pos/t8364.scala similarity index 100% rename from tests/pending/pos/t8364.scala rename to tests/pos/t8364.scala diff --git a/tests/pending/pos/trait-force-info.scala b/tests/pos/trait-force-info.scala similarity index 100% rename from tests/pending/pos/trait-force-info.scala rename to tests/pos/trait-force-info.scala From 05ba0abd71ef6e0aa281d32c0723bca515421697 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 22 Aug 2016 20:08:58 +0200 Subject: [PATCH 05/17] Be more careful with inserted casts. See comment on the commit for an explanation. --- src/dotty/tools/dotc/typer/Typer.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 39d9d267eb6a..10c69099dced 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1725,8 +1725,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit tree } else if (tree.tpe <:< pt) - if (ctx.typeComparer.GADTused) tree.asInstance(pt) - else tree + if (ctx.typeComparer.GADTused && pt.isValueType && ctx.settings.Ycheck.value.nonEmpty) + // Insert an explicit cast, so that -Ycheck in later phases succeeds. + // I suspect, but am not 100% sure that this might affect inferred types, + // if the expected type is a supertype of the GADT bound. It would be good to come + // up with a test case for this. For that reason, to be on the safe side + // we only insert the cast if there are Ychecks later on. + tree.asInstance(pt) + else + tree else if (wtp.isInstanceOf[MethodType]) missingArgs else { typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt") From 6d4469a627244eb0620a51764a3494f8250a8e2b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 23 Aug 2016 10:27:08 +0200 Subject: [PATCH 06/17] Retracting special case depending on Ycheck. I believe it's better to just bite the bullet and insert the cast. If it should become a problem, we can think of a fallback, e.g. marking the expression with a special tag, so that it does not get typechecked. But for the moment I am not sure it is an issue at all. --- src/dotty/tools/dotc/typer/Typer.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 10c69099dced..934ca556d06b 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1725,12 +1725,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit tree } else if (tree.tpe <:< pt) - if (ctx.typeComparer.GADTused && pt.isValueType && ctx.settings.Ycheck.value.nonEmpty) + if (ctx.typeComparer.GADTused && pt.isValueType) // Insert an explicit cast, so that -Ycheck in later phases succeeds. // I suspect, but am not 100% sure that this might affect inferred types, // if the expected type is a supertype of the GADT bound. It would be good to come - // up with a test case for this. For that reason, to be on the safe side - // we only insert the cast if there are Ychecks later on. + // up with a test case for this. tree.asInstance(pt) else tree From fcea3d54dd016600f5a96cda5d03f2a5ee81e7f1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 08:21:38 +0200 Subject: [PATCH 07/17] Implement alternative desugaring of for-if to filter. Fallback to .filter if a .withFilter is not available, but do this only for .withFilter calls generated from for expressions (this is different from what scalac does; the latter can also rewrite .withFilter calls given in source, which is not desirable. --- src/dotty/tools/dotc/ast/Desugar.scala | 16 ++++++++++++++-- src/dotty/tools/dotc/typer/Typer.scala | 12 +++++++++--- .../not-representable}/t7035.scala | 2 ++ .../not-representable}/t7228.scala | 1 + tests/pos/for-filter.scala | 12 ++++++++++++ 5 files changed, 38 insertions(+), 5 deletions(-) rename tests/{pending/pos => disabled/not-representable}/t7035.scala (84%) rename tests/{pending/pos => disabled/not-representable}/t7228.scala (94%) create mode 100644 tests/pos/for-filter.scala diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 346af42b8eba..500b28233973 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -8,6 +8,7 @@ import SymDenotations._, Symbols._, StdNames._, Annotations._, Trees._ import Decorators._ import language.higherKinds import collection.mutable.ListBuffer +import util.Attachment import config.Printers._ object desugar { @@ -17,6 +18,11 @@ object desugar { import untpd._ + /** Tags a .withFilter call generated by desugaring a for expression. + * Such calls can alternatively be rewritten to use filter. + */ + val MaybeFilter = new Attachment.Key[Unit] + /** Info of a variable in a pattern: The named tree and its type */ private type VarInfo = (NameTree, Tree) @@ -773,6 +779,12 @@ object desugar { (Bind(name, pat), Ident(name)) } + /** Add MaybeFilter attachment */ + def orFilter(tree: Tree): tree.type = { + tree.putAttachment(MaybeFilter, ()) + tree + } + /** Make a pattern filter: * rhs.withFilter { case pat => true case _ => false } * @@ -803,7 +815,7 @@ object desugar { val cases = List( CaseDef(pat, EmptyTree, Literal(Constant(true))), CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false)))) - Apply(Select(rhs, nme.withFilter), makeCaseLambda(cases)) + Apply(orFilter(Select(rhs, nme.withFilter)), makeCaseLambda(cases)) } /** Is pattern `pat` irrefutable when matched against `rhs`? @@ -858,7 +870,7 @@ object desugar { val vfrom1 = new IrrefutableGenFrom(makeTuple(allpats), rhs1) makeFor(mapName, flatMapName, vfrom1 :: rest1, body) case (gen: GenFrom) :: test :: rest => - val filtered = Apply(rhsSelect(gen, nme.withFilter), makeLambda(gen.pat, test)) + val filtered = Apply(orFilter(rhsSelect(gen, nme.withFilter)), makeLambda(gen.pat, test)) val genFrom = if (isIrrefutableGenFrom(gen)) new IrrefutableGenFrom(gen.pat, filtered) else GenFrom(gen.pat, filtered) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 934ca556d06b..c9a2e4b486af 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -346,11 +346,17 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - if (ctx.compilationUnit.isJava && tree.name.isTypeName) { + def selectWithFallback(fallBack: => Tree) = + tryEither(tryCtx => asSelect(tryCtx))((_, _) => fallBack) + + if (ctx.compilationUnit.isJava && tree.name.isTypeName) // SI-3120 Java uses the same syntax, A.B, to express selection from the // value A and from the type A. We have to try both. - tryEither(tryCtx => asSelect(tryCtx))((_, _) => asJavaSelectFromTypeTree(ctx)) - } else asSelect(ctx) + selectWithFallback(asJavaSelectFromTypeTree(ctx)) + else if (tree.name == nme.withFilter && tree.getAttachment(desugar.MaybeFilter).isDefined) + selectWithFallback(typedSelect(untpd.cpy.Select(tree)(tree.qualifier, nme.filter), pt)) + else + asSelect(ctx) } def typedSelectFromTypeTree(tree: untpd.SelectFromTypeTree, pt: Type)(implicit ctx: Context): Tree = track("typedSelectFromTypeTree") { diff --git a/tests/pending/pos/t7035.scala b/tests/disabled/not-representable/t7035.scala similarity index 84% rename from tests/pending/pos/t7035.scala rename to tests/disabled/not-representable/t7035.scala index f45bd0a878cc..b1ce66cc631b 100644 --- a/tests/pending/pos/t7035.scala +++ b/tests/disabled/not-representable/t7035.scala @@ -1,3 +1,5 @@ +// no longer works because dotty uses name-nased pattern matching for case classes + case class Y(final var x: Int, final private var y: String, final val z1: Boolean, final private val z2: Any) { import Test.{y => someY} diff --git a/tests/pending/pos/t7228.scala b/tests/disabled/not-representable/t7228.scala similarity index 94% rename from tests/pending/pos/t7228.scala rename to tests/disabled/not-representable/t7228.scala index 5d936f652901..525327857a6c 100644 --- a/tests/pending/pos/t7228.scala +++ b/tests/disabled/not-representable/t7228.scala @@ -1,3 +1,4 @@ +// no longer works because dotty does not have a concept of weak conformance object AdaptWithWeaklyConformantType { implicit class D(d: Double) { def double = d*2 } diff --git a/tests/pos/for-filter.scala b/tests/pos/for-filter.scala new file mode 100644 index 000000000000..3baac4f0ce68 --- /dev/null +++ b/tests/pos/for-filter.scala @@ -0,0 +1,12 @@ +object Test { + + case class C[T](xs: List[T]) { + def filter(p: T => Boolean) = new C(xs.filter(p)) + def map[U](f: T => U) = new C(xs.map(f)) + } + + def main(args: Array[String]): Unit = + println(for (x <- C(List(1, 2, 3)) if x % 2 == 0) yield x) + // println(C(List(1, 2, 3)).withFilter(_ % 2 == 0)) // error + +} From 880f46f2409067f56f2089763fe51dd7565384fe Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 08:33:01 +0200 Subject: [PATCH 08/17] Add more missing tests --- tests/disabled/not-testable/t5954a/A_1.scala | 6 ++++++ tests/disabled/not-testable/t5954a/B_2.scala | 6 ++++++ tests/disabled/not-testable/t5954b/A_1.scala | 6 ++++++ tests/disabled/not-testable/t5954b/B_2.scala | 5 +++++ tests/disabled/not-testable/t5954c/A_1.scala | 18 ++++++++++++++++++ tests/disabled/not-testable/t5954c/B_2.scala | 18 ++++++++++++++++++ tests/disabled/not-testable/t5954d/A_1.scala | 6 ++++++ tests/disabled/not-testable/t5954d/B_2.scala | 7 +++++++ 8 files changed, 72 insertions(+) create mode 100644 tests/disabled/not-testable/t5954a/A_1.scala create mode 100644 tests/disabled/not-testable/t5954a/B_2.scala create mode 100644 tests/disabled/not-testable/t5954b/A_1.scala create mode 100644 tests/disabled/not-testable/t5954b/B_2.scala create mode 100644 tests/disabled/not-testable/t5954c/A_1.scala create mode 100644 tests/disabled/not-testable/t5954c/B_2.scala create mode 100644 tests/disabled/not-testable/t5954d/A_1.scala create mode 100644 tests/disabled/not-testable/t5954d/B_2.scala diff --git a/tests/disabled/not-testable/t5954a/A_1.scala b/tests/disabled/not-testable/t5954a/A_1.scala new file mode 100644 index 000000000000..10ead0b1ca09 --- /dev/null +++ b/tests/disabled/not-testable/t5954a/A_1.scala @@ -0,0 +1,6 @@ +package p1 { + object `package` { + implicit class Foo(a: Any) + object Foo + } +} diff --git a/tests/disabled/not-testable/t5954a/B_2.scala b/tests/disabled/not-testable/t5954a/B_2.scala new file mode 100644 index 000000000000..10ead0b1ca09 --- /dev/null +++ b/tests/disabled/not-testable/t5954a/B_2.scala @@ -0,0 +1,6 @@ +package p1 { + object `package` { + implicit class Foo(a: Any) + object Foo + } +} diff --git a/tests/disabled/not-testable/t5954b/A_1.scala b/tests/disabled/not-testable/t5954b/A_1.scala new file mode 100644 index 000000000000..8465e8f8c6ce --- /dev/null +++ b/tests/disabled/not-testable/t5954b/A_1.scala @@ -0,0 +1,6 @@ +package p { + package object base { + class B + object B + } +} diff --git a/tests/disabled/not-testable/t5954b/B_2.scala b/tests/disabled/not-testable/t5954b/B_2.scala new file mode 100644 index 000000000000..f7e4704b3e62 --- /dev/null +++ b/tests/disabled/not-testable/t5954b/B_2.scala @@ -0,0 +1,5 @@ +package p { + package object base { + case class B() + } +} diff --git a/tests/disabled/not-testable/t5954c/A_1.scala b/tests/disabled/not-testable/t5954c/A_1.scala new file mode 100644 index 000000000000..29ad9547a232 --- /dev/null +++ b/tests/disabled/not-testable/t5954c/A_1.scala @@ -0,0 +1,18 @@ +package object A { + // these used to should be prevented by the implementation restriction + // but are now allowed + class B + object B + trait C + object C + case class D() + // all the rest of these should be ok + class E + object F + val g = "omg" + var h = "wtf" + def i = "lol" + type j = String + class K(val k : Int) extends AnyVal + implicit class L(val l : Int) +} diff --git a/tests/disabled/not-testable/t5954c/B_2.scala b/tests/disabled/not-testable/t5954c/B_2.scala new file mode 100644 index 000000000000..29ad9547a232 --- /dev/null +++ b/tests/disabled/not-testable/t5954c/B_2.scala @@ -0,0 +1,18 @@ +package object A { + // these used to should be prevented by the implementation restriction + // but are now allowed + class B + object B + trait C + object C + case class D() + // all the rest of these should be ok + class E + object F + val g = "omg" + var h = "wtf" + def i = "lol" + type j = String + class K(val k : Int) extends AnyVal + implicit class L(val l : Int) +} diff --git a/tests/disabled/not-testable/t5954d/A_1.scala b/tests/disabled/not-testable/t5954d/A_1.scala new file mode 100644 index 000000000000..8465e8f8c6ce --- /dev/null +++ b/tests/disabled/not-testable/t5954d/A_1.scala @@ -0,0 +1,6 @@ +package p { + package object base { + class B + object B + } +} diff --git a/tests/disabled/not-testable/t5954d/B_2.scala b/tests/disabled/not-testable/t5954d/B_2.scala new file mode 100644 index 000000000000..a4aa2eb587e1 --- /dev/null +++ b/tests/disabled/not-testable/t5954d/B_2.scala @@ -0,0 +1,7 @@ +package p { + trait T { + class B + object B + } + package object base extends T +} From 86d930bf89aa89e07fdc40ed40431ffea2085090 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 08:40:28 +0200 Subject: [PATCH 09/17] Drop out of date comment --- tests/pos/gadts2.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pos/gadts2.scala b/tests/pos/gadts2.scala index 71089c0f7872..bdf1c8e8af2d 100644 --- a/tests/pos/gadts2.scala +++ b/tests/pos/gadts2.scala @@ -10,7 +10,7 @@ object Test { def f[A](t: Term[A], c: Cell[A]): Unit = { t match { - case NumTerm(n) => c.x = MyDouble(1.0) // problem is: this assignment is not type correct, since gadt variable is forgotten + case NumTerm(n) => c.x = MyDouble(1.0) } } From f8970818e3d285b7827a035bffb26c1a4b97319e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 09:50:42 +0200 Subject: [PATCH 10/17] Type annotations in context enclosing the annotated definition Fixes SI-7426, which caused a double definition before. --- src/dotty/tools/dotc/typer/Typer.scala | 3 ++- tests/{pending => }/pos/t7426.scala | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename tests/{pending => }/pos/t7426.scala (100%) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index c9a2e4b486af..f0086b0ab892 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1072,8 +1072,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def completeAnnotations(mdef: untpd.MemberDef, sym: Symbol)(implicit ctx: Context): Unit = { // necessary to force annotation trees to be computed. sym.annotations.foreach(_.tree) + val annotCtx = ctx.outersIterator.dropWhile(_.owner == sym).next // necessary in order to mark the typed ahead annotations as definitely typed: - untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation) + untpd.modsDeco(mdef).mods.annotations.foreach(typedAnnotation(_)(annotCtx)) } def typedAnnotation(annot: untpd.Tree)(implicit ctx: Context): Tree = track("typedAnnotation") { diff --git a/tests/pending/pos/t7426.scala b/tests/pos/t7426.scala similarity index 100% rename from tests/pending/pos/t7426.scala rename to tests/pos/t7426.scala From eb529b556f92a5ab0329899762b43eea7103ad59 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 12:37:50 +0200 Subject: [PATCH 11/17] Generalize self-referential member comparisons. The special case in hasMatchingMember dealing with self-refential members has to be generalized to deal lower and upper bounds. Test case is t762.scala --- src/dotty/tools/dotc/core/TypeComparer.scala | 8 +++++--- tests/pending/pos/t762.scala | 2 -- tests/pos/t762.scala | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 tests/pending/pos/t762.scala create mode 100644 tests/pos/t762.scala diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index e9300c0ba2c0..538a74198672 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -861,11 +861,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { // special case for situations like: // class C { type T } // val foo: C - // foo.type <: C { type T = foo.T } + // foo.type <: C { type T {= , <: , >:} foo.T } def selfReferentialMatch = tp1.isInstanceOf[SingletonType] && { rinfo2 match { - case rinfo2: TypeAlias => - !defn.isBottomType(tp1.widen) && (tp1 select name) =:= rinfo2.alias + case rinfo2: TypeBounds => + val mbr1 = tp1.select(name) + !defn.isBottomType(tp1.widen) && + (mbr1 =:= rinfo2.hi || (rinfo2.hi ne rinfo2.lo) && mbr1 =:= rinfo2.lo) case _ => false } } diff --git a/tests/pending/pos/t762.scala b/tests/pending/pos/t762.scala deleted file mode 100644 index 76860272eafd..000000000000 --- a/tests/pending/pos/t762.scala +++ /dev/null @@ -1,2 +0,0 @@ -trait Foo { type T } -trait Bar extends Foo { val x : Foo { type T <: Bar.this.T } = this : this.type } diff --git a/tests/pos/t762.scala b/tests/pos/t762.scala new file mode 100644 index 000000000000..c5bf39b0c3f8 --- /dev/null +++ b/tests/pos/t762.scala @@ -0,0 +1,4 @@ +trait Foo { type T } +trait Bar1 extends Foo { val x : Foo { type T <: Bar1.this.T } = this } +trait Bar2 extends Foo { val x : Foo { type T = Bar2.this.T } = this } +trait Bar3 extends Foo { val x : Foo { type T >: Bar3.this.T } = this } From b41cff6fa4ccc593916790364424051d9eef200d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 12:38:22 +0200 Subject: [PATCH 12/17] Test recategorization --- tests/{pending/pos => neg}/t7239.scala | 10 ++++++---- tests/{pending/pos => pos-scala2}/t7688.scala | 0 2 files changed, 6 insertions(+), 4 deletions(-) rename tests/{pending/pos => neg}/t7239.scala (72%) rename tests/{pending/pos => pos-scala2}/t7688.scala (100%) diff --git a/tests/pending/pos/t7239.scala b/tests/neg/t7239.scala similarity index 72% rename from tests/pending/pos/t7239.scala rename to tests/neg/t7239.scala index 16e9d00f1733..f3a379b4eba5 100644 --- a/tests/pending/pos/t7239.scala +++ b/tests/neg/t7239.scala @@ -1,3 +1,5 @@ +// Dotty rewrites only withFilter calls occurring in for expressions to filter calls. +// So this test does not compile. object Test { def BrokenMethod(): HasFilter[(Int, String)] = ??? @@ -15,12 +17,12 @@ object Test { (implicit F0: NoImplicit): HasWithFilter = ??? } - BrokenMethod().withFilter(_ => true) // okay - BrokenMethod().filter(_ => true) // okay + BrokenMethod().withFilter(_ => true) // error + BrokenMethod().filter(_ => true) // ok locally { import addWithFilter._ - BrokenMethod().withFilter((_: (Int, String)) => true) // okay + BrokenMethod().withFilter((_: (Int, String)) => true) // error } locally { @@ -33,6 +35,6 @@ object Test { // `(B => Boolean)`. Only later during pickling does the // defensive check for erroneous types in the tree pick up // the problem. - BrokenMethod().withFilter(x => true) // erroneous or inaccessible type. + BrokenMethod().withFilter(x => true) // error } } diff --git a/tests/pending/pos/t7688.scala b/tests/pos-scala2/t7688.scala similarity index 100% rename from tests/pending/pos/t7688.scala rename to tests/pos-scala2/t7688.scala From e1dc0b46a81a507ca040dca05a98f49fd6520d25 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 13:48:26 +0200 Subject: [PATCH 13/17] Move tests to right directory --- tests/disabled/not-representable/{ => pos}/t3999b.scala | 0 .../not-representable/pos}/t5544/Api_1.scala | 1 + .../not-representable/pos}/t5544/Test_2.scala | 0 tests/disabled/not-representable/{ => pos}/t7035.scala | 0 tests/disabled/not-representable/{ => pos}/t7228.scala | 0 tests/pending/neg/i533/Compat.scala | 7 +++++++ tests/pending/neg/i533/JA.java | 5 +++++ 7 files changed, 13 insertions(+) rename tests/disabled/not-representable/{ => pos}/t3999b.scala (100%) rename tests/{run => disabled/not-representable/pos}/t5544/Api_1.scala (72%) rename tests/{run => disabled/not-representable/pos}/t5544/Test_2.scala (100%) rename tests/disabled/not-representable/{ => pos}/t7035.scala (100%) rename tests/disabled/not-representable/{ => pos}/t7228.scala (100%) create mode 100644 tests/pending/neg/i533/Compat.scala create mode 100644 tests/pending/neg/i533/JA.java diff --git a/tests/disabled/not-representable/t3999b.scala b/tests/disabled/not-representable/pos/t3999b.scala similarity index 100% rename from tests/disabled/not-representable/t3999b.scala rename to tests/disabled/not-representable/pos/t3999b.scala diff --git a/tests/run/t5544/Api_1.scala b/tests/disabled/not-representable/pos/t5544/Api_1.scala similarity index 72% rename from tests/run/t5544/Api_1.scala rename to tests/disabled/not-representable/pos/t5544/Api_1.scala index b4c92864de5c..30994fa0708f 100644 --- a/tests/run/t5544/Api_1.scala +++ b/tests/disabled/not-representable/pos/t5544/Api_1.scala @@ -1,3 +1,4 @@ +// Uses structural types; therefore not expressible in dotty import scala.annotation.StaticAnnotation class ann(val bar: Any) extends StaticAnnotation diff --git a/tests/run/t5544/Test_2.scala b/tests/disabled/not-representable/pos/t5544/Test_2.scala similarity index 100% rename from tests/run/t5544/Test_2.scala rename to tests/disabled/not-representable/pos/t5544/Test_2.scala diff --git a/tests/disabled/not-representable/t7035.scala b/tests/disabled/not-representable/pos/t7035.scala similarity index 100% rename from tests/disabled/not-representable/t7035.scala rename to tests/disabled/not-representable/pos/t7035.scala diff --git a/tests/disabled/not-representable/t7228.scala b/tests/disabled/not-representable/pos/t7228.scala similarity index 100% rename from tests/disabled/not-representable/t7228.scala rename to tests/disabled/not-representable/pos/t7228.scala diff --git a/tests/pending/neg/i533/Compat.scala b/tests/pending/neg/i533/Compat.scala new file mode 100644 index 000000000000..16613cf5b9a8 --- /dev/null +++ b/tests/pending/neg/i533/Compat.scala @@ -0,0 +1,7 @@ +object Compat { + def main(args: Array[String]): Unit = { + val x = new Array[Int](1) + x(0) = 10 + println(JA.get(x)) + } +} diff --git a/tests/pending/neg/i533/JA.java b/tests/pending/neg/i533/JA.java new file mode 100644 index 000000000000..92421e5b1fee --- /dev/null +++ b/tests/pending/neg/i533/JA.java @@ -0,0 +1,5 @@ +class JA { + public static T get(T[] arr) { + return arr[0]; + } +} \ No newline at end of file From bdb425c57128c85fc3f7bd03b1906f55805d2194 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 15:06:30 +0200 Subject: [PATCH 14/17] Relax matching requirement in unApply We now always widen selector type to the superclass if necessary, no matter whether the selector type refers to a trait or a proper class. --- src/dotty/tools/dotc/typer/Applications.scala | 5 ++--- tests/{pending => }/pos/t7294.scala | 0 2 files changed, 2 insertions(+), 3 deletions(-) rename tests/{pending => }/pos/t7294.scala (100%) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 45ed4d93858d..099105de359a 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -775,14 +775,13 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * The generalizations of a type T are the smallest set G such that * * - T is in G - * - If a typeref R in G represents a trait, R's superclass is in G. + * - If a typeref R in G represents a class or trait, R's superclass is in G. * - If a type proxy P is not a reference to a class, P's supertype is in G */ def isSubTypeOfParent(subtp: Type, tp: Type)(implicit ctx: Context): Boolean = if (subtp <:< tp) true else tp match { - case tp: TypeRef if tp.symbol.isClass => - tp.symbol.is(Trait) && isSubTypeOfParent(subtp, tp.firstParent) + case tp: TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParent) case tp: TypeProxy => isSubTypeOfParent(subtp, tp.superType) case _ => false } diff --git a/tests/pending/pos/t7294.scala b/tests/pos/t7294.scala similarity index 100% rename from tests/pending/pos/t7294.scala rename to tests/pos/t7294.scala From 55ad7ebb5960ed7590610c777cce229f7241c0d3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 24 Aug 2016 15:07:14 +0200 Subject: [PATCH 15/17] Make inherited inferred result type work for dependent methods We did not properly rename parameter references before. --- src/dotty/tools/dotc/typer/Namer.scala | 27 ++++++++++++++++---------- tests/{pending => }/pos/t7668.scala | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) rename tests/{pending => }/pos/t7668.scala (78%) diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 3c0a45e946c5..d90f37860545 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -726,7 +726,7 @@ class Namer { typer: Typer => // the parent types are elaborated. index(constr) symbolOfTree(constr).ensureCompleted() - + index(rest)(inClassContext(selfInfo)) val tparamAccessors = decls.filter(_ is TypeParamAccessor).toList @@ -807,20 +807,27 @@ class Namer { typer: Typer => lazy val schema = paramFn(WildcardType) val site = sym.owner.thisType ((NoType: Type) /: sym.owner.info.baseClasses.tail) { (tp, cls) => - val iRawInfo = - cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema).info - val iInstInfo = iRawInfo match { - case iRawInfo: PolyType => - if (iRawInfo.paramNames.length == typeParams.length) - iRawInfo.instantiate(typeParams map (_.typeRef)) + def instantiatedResType(info: Type, tparams: List[Symbol], paramss: List[List[Symbol]]): Type = info match { + case info: PolyType => + if (info.paramNames.length == typeParams.length) + instantiatedResType(info.instantiate(tparams.map(_.typeRef)), Nil, paramss) else NoType + case info: MethodType => + paramss match { + case params :: paramss1 if info.paramNames.length == params.length => + instantiatedResType(info.instantiate(params.map(_.termRef)), tparams, paramss1) + case _ => + NoType + } case _ => - if (typeParams.isEmpty) iRawInfo + if (tparams.isEmpty && paramss.isEmpty) info.widenExpr else NoType } - val iResType = iInstInfo.finalResultType.asSeenFrom(site, cls) + val iRawInfo = + cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema).info + val iResType = instantiatedResType(iRawInfo, typeParams, paramss).asSeenFrom(site, cls) if (iResType.exists) - typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inst: $iInstInfo, inherited: $iResType") + typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inherited: $iResType") tp & iResType } } diff --git a/tests/pending/pos/t7668.scala b/tests/pos/t7668.scala similarity index 78% rename from tests/pending/pos/t7668.scala rename to tests/pos/t7668.scala index 222a13d03902..6657ffab6cb1 100644 --- a/tests/pending/pos/t7668.scala +++ b/tests/pos/t7668.scala @@ -8,5 +8,5 @@ trait Extractor { } class Sub extends Extractor { - def extract(s: Space) = s.x + def extract(ss: Space) = ss.x } From 910aa4b4b6b1db98148566ca0b46e026fd5e312d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 25 Aug 2016 14:27:12 +0200 Subject: [PATCH 16/17] More tests recategorized --- tests/{pending => disabled/not-representable}/pos/t8111.scala | 1 + tests/{pending => disabled/typetags}/pos/t8237b.scala | 0 tests/{pending/pos => neg}/t8002-nested-scope.scala | 2 +- tests/pending/pos/infersingle.flags | 1 - tests/pending/pos/trait-force-info.flags | 1 - 5 files changed, 2 insertions(+), 3 deletions(-) rename tests/{pending => disabled/not-representable}/pos/t8111.scala (94%) rename tests/{pending => disabled/typetags}/pos/t8237b.scala (100%) rename tests/{pending/pos => neg}/t8002-nested-scope.scala (89%) delete mode 100644 tests/pending/pos/infersingle.flags delete mode 100644 tests/pending/pos/trait-force-info.flags diff --git a/tests/pending/pos/t8111.scala b/tests/disabled/not-representable/pos/t8111.scala similarity index 94% rename from tests/pending/pos/t8111.scala rename to tests/disabled/not-representable/pos/t8111.scala index 3f0e766ce5c1..04a8e20de1ea 100644 --- a/tests/pending/pos/t8111.scala +++ b/tests/disabled/not-representable/pos/t8111.scala @@ -1,3 +1,4 @@ +// structural types, cannot represent trait T { def crashy(ma: Any): Unit = { diff --git a/tests/pending/pos/t8237b.scala b/tests/disabled/typetags/pos/t8237b.scala similarity index 100% rename from tests/pending/pos/t8237b.scala rename to tests/disabled/typetags/pos/t8237b.scala diff --git a/tests/pending/pos/t8002-nested-scope.scala b/tests/neg/t8002-nested-scope.scala similarity index 89% rename from tests/pending/pos/t8002-nested-scope.scala rename to tests/neg/t8002-nested-scope.scala index a2088bce7a0f..78a03ce66940 100644 --- a/tests/pending/pos/t8002-nested-scope.scala +++ b/tests/neg/t8002-nested-scope.scala @@ -13,7 +13,7 @@ class C { { val a = 0 object C { - new C().x + new C().x // error: cannot be accessed } } } diff --git a/tests/pending/pos/infersingle.flags b/tests/pending/pos/infersingle.flags deleted file mode 100644 index e1b37447c953..000000000000 --- a/tests/pending/pos/infersingle.flags +++ /dev/null @@ -1 +0,0 @@ --Xexperimental \ No newline at end of file diff --git a/tests/pending/pos/trait-force-info.flags b/tests/pending/pos/trait-force-info.flags deleted file mode 100644 index eb4d19bcb91a..000000000000 --- a/tests/pending/pos/trait-force-info.flags +++ /dev/null @@ -1 +0,0 @@ --optimise \ No newline at end of file From e61ff6f4cfb632b11b7e54e2904706d382634eda Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 26 Aug 2016 11:31:52 +0200 Subject: [PATCH 17/17] Dependent method tests --- .../pos/depmet_implicit_oopsla_zipwith.scala | 0 tests/pending/pos/depmet_implicit_norm_ret.scala | 9 +++++++-- tests/pos/dependent-implicits.scala | 7 +++++++ tests/pos/t5070.scala | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) rename tests/{pending => disabled/structural-type}/pos/depmet_implicit_oopsla_zipwith.scala (100%) create mode 100644 tests/pos/dependent-implicits.scala create mode 100644 tests/pos/t5070.scala diff --git a/tests/pending/pos/depmet_implicit_oopsla_zipwith.scala b/tests/disabled/structural-type/pos/depmet_implicit_oopsla_zipwith.scala similarity index 100% rename from tests/pending/pos/depmet_implicit_oopsla_zipwith.scala rename to tests/disabled/structural-type/pos/depmet_implicit_oopsla_zipwith.scala diff --git a/tests/pending/pos/depmet_implicit_norm_ret.scala b/tests/pending/pos/depmet_implicit_norm_ret.scala index 85be750b4296..42bfb9fe16e2 100644 --- a/tests/pending/pos/depmet_implicit_norm_ret.scala +++ b/tests/pending/pos/depmet_implicit_norm_ret.scala @@ -17,6 +17,8 @@ object Test{ } } + import ZipWith._ + trait ZipWith[S] { type T def zipWith : S => T = sys.error("") @@ -24,6 +26,9 @@ object Test{ // bug: inferred return type = (Stream[A]) => java.lang.Object with Test.ZipWith[B]{type T = Stream[B]}#T // this seems incompatible with vvvvvvvvvvvvvvvvvvvvvv -- #3731 - def map[A,B](f : A => B) /* : Stream[A] => Stream[B]*/ = ZipWith(f) - val tst: Stream[Int] = map{x: String => x.length}(Stream("a")) + def map1[A,B](f : A => B) = ZipWith(f)(SuccZipWith) // this typechecks but fails in -Ycheck:first + val tst1: Stream[Int] = map1[String, Int]{x: String => x.length}.apply(Stream("a")) + + def map2[A,B](f : A => B) = ZipWith(f) // this finds ZeroZipWith where scalac finds SuccZipWith and fails typechecking in the next line. + val tst2: Stream[Int] = map2{x: String => x.length}.apply(Stream("a")) } diff --git a/tests/pos/dependent-implicits.scala b/tests/pos/dependent-implicits.scala new file mode 100644 index 000000000000..17a323112473 --- /dev/null +++ b/tests/pos/dependent-implicits.scala @@ -0,0 +1,7 @@ +object Test { + trait T { type X; val x: X } + implicit def f(x: T): x.X = x.x + val t = new T { type X = String; val x = "" } + val x: String = t + val uy: String = f(t) +} diff --git a/tests/pos/t5070.scala b/tests/pos/t5070.scala new file mode 100644 index 000000000000..410afba148a1 --- /dev/null +++ b/tests/pos/t5070.scala @@ -0,0 +1,15 @@ +trait A { + type T +} + +object O { + implicit def b(implicit x: A): x.T = error("") +} + +class Test { + import O._ + implicit val a: A = new A {} + implicitly[a.T] // works + + implicitly[a.T](b(a)) // works +}