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

check exhaustivity involving user-defined extractors with precise return type

    Details

      Description

      The following code fails to produce a non-exhaustive pattern warning when compiled with Scala 2.9.0-RC3 and above. The warning does get emitted with versions 2.9.0-RC2 and 2.8.1.

      sealed trait Node
      
      class NodeType1 (val a:Int) extends Node
      class NodeType2 (val b:Int) extends Node
      
      object NodeType1 {
        def unapply (x : NodeType1) : Some[Int] = Some(x.a)
      }
      
      object NodeType2 {
        def unapply (x : NodeType2) : Some[Int] = Some(x.b)
      }
      
      object Test {
        def test (x: Node) = x match {
          case NodeType1(a) => "got node type 1 " + a 
        }
      }
      

        Activity

        Hide
        Paul Phillips added a comment -

        I apologize for reopening this given that I've seen you deal with like 150 tickets today, but I need more convincing and I don't want it get buried.

        Show
        Paul Phillips added a comment - I apologize for reopening this given that I've seen you deal with like 150 tickets today, but I need more convincing and I don't want it get buried.
        Hide
        Adriaan Moors added a comment -

        Thanks. I agree that the Some[T] result type (which I missed – my vision went a bit blurry around #139) should tell us something. We can only hope it's not Some(Math.random) they're returning.

        Show
        Adriaan Moors added a comment - Thanks. I agree that the Some [T] result type (which I missed – my vision went a bit blurry around #139) should tell us something. We can only hope it's not Some(Math.random) they're returning.
        Hide
        Paul Phillips added a comment -

        They can return Math.random if they want. An extractor covers Bar1 because the method parameter type is Bar1 and the return is Some[T]. The values are immaterial. We can hope against Math.random on general principles though if you like.

        Show
        Paul Phillips added a comment - They can return Math.random if they want. An extractor covers Bar1 because the method parameter type is Bar1 and the return is Some [T] . The values are immaterial. We can hope against Math.random on general principles though if you like.
        Hide
        Adriaan Moors added a comment -

        Yes. General principles. That's what I was thinking of. And sleep.

        Show
        Adriaan Moors added a comment - Yes. General principles. That's what I was thinking of. And sleep.
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/824

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Arseniy Alekseyev
          • Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Due:
              Created:
              Updated:
              Resolved:

              Development