SI-6968 Simple Tuple patterns aren't irrefutable #1893

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Owner

retronym commented Jan 13, 2013

Reverts part of c82ecab. The parser can't assume that
a pattern (a, b) will match, as results of
.isInstanceOf[Tuple2] can't be statically known until
after the typer.

The reopens SI-1336 and SI-5589, in exchange for fixing
this regression SI-6968. Keeping all three fixed will require
some major surgery.

Review by @paulp

SI-6968 Simple Tuple patterns aren't irrefutable
Reverts part of c82ecab. The parser can't assume that
a pattern `(a, b)` will match, as results of
`.isInstanceOf[Tuple2]` can't be statically known until
after the typer.

The reopens SI-1336 and SI-5589, in exchange for fixing
this regression SI-6968. Keeping all three fixed will require
some major surgery.
Owner

adriaanm commented Jan 14, 2013

testing: [...]/files/neg/t5589neg2.scala
t5589neg2.scala:7: error: constructor cannot be instantiated to expected type;
 found   : (T1, T2)
 required: String
    for (((((a, (b, (c, (d1, d2)))), es), fs), gs) <- x) yield (d :: es).mkString(", ") // not ok
                        ^
one error found

testing: [...]/files/run/t4574.scala
java.lang.AssertionError: assertion failed: Should not succeed.
    at Test$.expectMatchError(t4574.scala:5)

    at Test$.main(t4574.scala:10)

testing: [...]/files/scalacheck/parallel-collections
ParallelMapCheck1.scala:23: error: constructor cannot be instantiated to expected type;
 found   : (T1, T2)
 required: scala.collection.parallel.ParMap[K,V]
    val containsSelf = for ((k, v) <- coll) yield (coll.get(k) == Some(v))
                            ^
one error found
Owner

retronym commented Jan 21, 2013

Closing this, back in a day or two. There is another problem: the refutability checking in RefChecks, albeit somewhat ineffectual and now sometimes obviated by the (slightly overeager) checking in the parser, no longer works at all.

It suffers from two problems:

     case Apply(
        Select(qual, nme.filter | nme.withFilter),
        List(Function(
          List(ValDef(_, pname, tpt, _)),
          Match(_, CaseDef(pat1, _, _) :: _))))
        if ((pname startsWith nme.CHECK_IF_REFUTABLE_STRING) &&
            isIrrefutable(pat1, tpt.tpe) && (qual.tpe <:< tree.tpe)) =>

          transform(qual)
  • It doesn't handle TypeApply, the sort of problem that is now easily solved with treeInfo.Applied.
  • match nodes are eliminated by patmat under the new pattern matcher.

I've got a fix coming that uses the results of pattern matcher unreachability analysis (re-run with different assumptions about nullability) to make this work again.

@retronym retronym closed this Jan 21, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment