Scala Programming Language
  1. Scala Programming Language
  2. SI-6282

uncheckable warning for unapply with intersection including abstract type

    Details

      Description

      import scala.reflect.runtime.universe._
      
      object Test {
        object Bippy {
          def unapply(x: Apply with Select) = Some(x.qualifier)
        }
        def main(args: Array[String]): Unit = {
          val x = Apply(EmptyTree, Nil)
          // Direct invocation correctly disallowed
          // Bippy.unapply(x)
          //
          // Pattern matcher allows, unsoundly
          x match { case Bippy(_) => () }
        }
      }
      // and...
      //
      // java.lang.ClassCastException: scala.reflect.internal.Trees$Apply cannot be cast to scala.reflect.api.Trees$SelectApi
      //   at Test$Bippy$.unapply(a.scala:5)
      //   at Test$.main(a.scala:13)
      //   at Test.main(a.scala)
      

        Activity

        Hide
        Paul Phillips added a comment -

        Putting 2+2 together, I keep running across this code and thinking "how can this be right?" but I forgot I'd opened this bug. I can't follow the logic at a glance, but this unlikely treatment of intersection types feels relevant.

        // if at least one of the types in an intersection is checkable, use the checkable ones
        // this avoids problems as in run/matchonseq.scala, where the expected type is `Coll with scala.collection.SeqLike`
        // Coll is an abstract type, but SeqLike of course is not
        case RefinedType(ps, _) if ps.length > 1 && (ps exists infer.isCheckable) =>
          None
        
        Show
        Paul Phillips added a comment - Putting 2+2 together, I keep running across this code and thinking "how can this be right?" but I forgot I'd opened this bug. I can't follow the logic at a glance, but this unlikely treatment of intersection types feels relevant. // if at least one of the types in an intersection is checkable, use the checkable ones // this avoids problems as in run/matchonseq.scala, where the expected type is `Coll with scala.collection.SeqLike` // Coll is an abstract type, but SeqLike of course is not case RefinedType(ps, _) if ps.length > 1 && (ps exists infer.isCheckable) => None
        Hide
        James Iry added a comment -

        2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

        Show
        James Iry added a comment - 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:

              Development