From 7b9853a70d6af27bc1989c9bf5a09a302093978b Mon Sep 17 00:00:00 2001 From: "Paolo G. Giarrusso" Date: Wed, 30 May 2018 15:07:56 +0200 Subject: [PATCH] Stop rewriting withFilter to filter This was dropped for Scala 2 in scala/scala#5252 for 2.12.0-RC1, as discussed for instance in scala/bug#6455 and scala/bug#8339. Beyond this code, also remove `MaybeFilter` attachment and attending code introduced in fcea3d54dd016600f5a96cda5d03f2a5ee81e7f1. A caveat is that, unexpectedly, this code was added in 2016-08-24, after scala/scala#5252 was merged, as if the decision was reversed; but #1461 says: > Also, I went through tests in pending/pos and reclassified as far as possible. So I assume this just happened because the Scala 2 PR didn't remove our pending test. --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 16 ++-------------- compiler/src/dotty/tools/dotc/typer/Typer.scala | 5 ----- tests/{untried => }/neg/t6455.scala | 2 +- tests/pos/for-filter.scala | 12 ------------ tests/untried/neg/t6455.check | 4 ---- 5 files changed, 3 insertions(+), 36 deletions(-) rename tests/{untried => }/neg/t6455.scala (78%) delete mode 100644 tests/pos/for-filter.scala delete mode 100644 tests/untried/neg/t6455.check diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0ae11faf502b..d4582ac695c0 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -10,7 +10,6 @@ import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName} import language.higherKinds import typer.FrontEnd import collection.mutable.ListBuffer -import util.Property import reporting.diagnostic.messages._ import reporting.trace @@ -18,11 +17,6 @@ object desugar { import untpd._ import DesugarEnums._ - /** Tags a .withFilter call generated by desugaring a for expression. - * Such calls can alternatively be rewritten to use filter. - */ - val MaybeFilter = new Property.Key[Unit] - /** Info of a variable in a pattern: The named tree and its type */ private type VarInfo = (NameTree, Tree) @@ -992,12 +986,6 @@ 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 } * @@ -1028,7 +1016,7 @@ object desugar { val cases = List( CaseDef(pat, EmptyTree, Literal(Constant(true))), CaseDef(Ident(nme.WILDCARD), EmptyTree, Literal(Constant(false)))) - Apply(orFilter(Select(rhs, nme.withFilter)), makeCaseLambda(cases)) + Apply(Select(rhs, nme.withFilter), makeCaseLambda(cases)) } /** Is pattern `pat` irrefutable when matched against `rhs`? @@ -1085,7 +1073,7 @@ object desugar { val vfrom1 = new IrrefutableGenFrom(makeTuple(allpats), rhs1) makeFor(mapName, flatMapName, vfrom1 :: rest1, body) case (gen: GenFrom) :: test :: rest => - val filtered = Apply(orFilter(rhsSelect(gen, nme.withFilter)), makeLambda(gen.pat, test)) + val filtered = Apply(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/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index f9c7fdaeef7b..9e34deeb2555 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -462,11 +462,6 @@ class Typer extends Namer // 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. selectWithFallback(tryJavaSelectOnType(_)) // !!! possibly exponential bcs of qualifier retyping - else if (tree.name == nme.withFilter && tree.getAttachment(desugar.MaybeFilter).isDefined) - selectWithFallback { - implicit ctx => - typedSelect(untpd.cpy.Select(tree)(tree.qualifier, nme.filter), pt) // !!! possibly exponential bcs of qualifier retyping - } else typeSelectOnTerm(ctx) } diff --git a/tests/untried/neg/t6455.scala b/tests/neg/t6455.scala similarity index 78% rename from tests/untried/neg/t6455.scala rename to tests/neg/t6455.scala index f62be3eb0dad..ab656a7acf27 100644 --- a/tests/untried/neg/t6455.scala +++ b/tests/neg/t6455.scala @@ -2,5 +2,5 @@ object O { def filter(p: Int => Boolean): O.type = this } class Test { // should not compile because we no longer rewrite withFilter => filter under -Xfuture - O.withFilter(f => true) + O.withFilter(f => true) // error // error } diff --git a/tests/pos/for-filter.scala b/tests/pos/for-filter.scala deleted file mode 100644 index 3baac4f0ce68..000000000000 --- a/tests/pos/for-filter.scala +++ /dev/null @@ -1,12 +0,0 @@ -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 - -} diff --git a/tests/untried/neg/t6455.check b/tests/untried/neg/t6455.check deleted file mode 100644 index 8f2aad0b9e67..000000000000 --- a/tests/untried/neg/t6455.check +++ /dev/null @@ -1,4 +0,0 @@ -t6455.scala:5: error: value withFilter is not a member of object O - O.withFilter(f => true) - ^ -one error found