Skip to content

Commit

Permalink
Discovered filter was still being generated.
Browse files Browse the repository at this point in the history
Rather than withFilter, for a subset of for comprehension structures.
Not sure if this was somewhat by design - only seems possible because
refchecks was only looking for nme.filter, not nme.withFilter, so
perhaps this was intended as some secret irrefutability backchannel?
Really have to document that sort of thing if it's intentional.  I
assumed it wasn't and unified everything.
  • Loading branch information
paulp committed Mar 20, 2012
1 parent c82ecab commit 365bb2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ abstract class TreeBuilder {
)
val matchTree = makeVisitor(cases, false, scrutineeName)

atPos(tree.pos)(Apply(Select(tree, nme.filter), matchTree :: Nil))
atPos(tree.pos)(Apply(Select(tree, nme.withFilter), matchTree :: Nil))
}

/** Create tree for for-comprehension generator <val pat0 <- rhs0> */
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R

private def transformApply(tree: Apply): Tree = tree match {
case Apply(
Select(qual, nme.filter),
Select(qual, nme.filter | nme.withFilter),
List(Function(
List(ValDef(_, pname, tpt, _)),
Match(_, CaseDef(pat1, _, _) :: _))))
Expand Down
22 changes: 22 additions & 0 deletions test/files/pos/irrefutable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// The test which this should perform but does not
// is that f1 is recognized as irrefutable and f2 is not
// This can be recognized via the generated classes:
//
// A$$anonfun$f1$1.class
// A$$anonfun$f2$1.class
// A$$anonfun$f2$2.class
//
// The extra one in $f2$ is the filter.
//
// !!! Marking with exclamation points so maybe someday
// this test will be finished.
class A {
case class Foo[T](x: T)

def f1(xs: List[Foo[Int]]) = {
for (Foo(x: Int) <- xs) yield x
}
def f2(xs: List[Foo[Any]]) = {
for (Foo(x: Int) <- xs) yield x
}
}

0 comments on commit 365bb2b

Please sign in to comment.