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

spurious unreachability error due to Product not conforming to AnyRef

    Details

      Description

      (null: Any) match {
        case x: AnyRef if false =>
        case list: Option[Int] =>
        case product: Product => // change Product to String and it's all good
      }
      

      due to the way the subtyping relations are rendered as boolean propositions, we get a contradiction, and the error shows up in an unexpected case:

      [adriaan@lampmac13 scala (topic/virtpatmat-dev)]$ qs -Ypatmat-debug
      Welcome to Scala version 2.10.0-20120705-095737-584eeecd82 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_33).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> (null: Any) match {
           |   case x: AnyRef if false => // has to be AnyRef
           |   case list: Option[Int] => // has to be a product-derived class
           |   case product: Product => // apparently Product is not a subtype of AnyRef (or AnyVal)
           | }
      
      <snip>
      
      NOT excludes: (Product,Option[_])
      excludes    : (Product,Product,AnyRef,AnyRef,false,false,false,false)
      excludes    : (Product,Product,null,Null(null),false,false,true,true)
      
      eq axioms for: Product
      excluded: List(V1=AnyRef#2, V1=null#1)
      implied: List()
      NOT excludes: (Option[_],Product)
      NOT excludes: (Option[_],AnyRef)
      excludes    : (Option[_],Option[_],null,Null(null),false,false,true,true)
      
      eq axioms for: Option[_]
      excluded: List(V1=null#1)
      implied: List(V1=Product#4, V1=AnyRef#2)
      NOT excludes: (AnyRef,Option[_])
      excludes    : (AnyRef,AnyRef,null,Null(null),false,false,true,true)
      
      eq axioms for: AnyRef
      excluded: List(V1=null#1)
      implied: List()
      
      eq axioms for: null
      excluded: List()
      implied: List()
      

        Activity

        Hide
        Adriaan Moors added a comment - - edited
        Show
        Adriaan Moors added a comment - - edited https://github.com/scala/scala/pull/874
        Hide
        Adriaan Moors added a comment -

        seems to have regressed without being caught by the test (grep for "unreachable code" in https://scala-webapps.epfl.ch/jenkins/job/scala-nightly-main/1514/consoleText)

        Show
        Adriaan Moors added a comment - seems to have regressed without being caught by the test (grep for "unreachable code" in https://scala-webapps.epfl.ch/jenkins/job/scala-nightly-main/1514/consoleText )
        Hide
        Adriaan Moors added a comment - - edited

        this should not warn:

        trait A
        trait B
        trait C
        trait AB extends B with A
        
        object Test extends App {
          def foo(x: Any) = x match {
            case _ : C  => println("C")
            case _ : AB => println("AB")
            case _ : B  => println("B")
            case _ : A  => println("A")
          }
        
          foo(new A {})
          foo(new B {})
          foo(new AB{})
          foo(new C {})
        }
        

        prints:

        A
        B
        AB
        C
        
        Show
        Adriaan Moors added a comment - - edited this should not warn: trait A trait B trait C trait AB extends B with A object Test extends App { def foo(x: Any) = x match { case _ : C => println("C") case _ : AB => println("AB") case _ : B => println("B") case _ : A => println("A") } foo(new A {}) foo(new B {}) foo(new AB{}) foo(new C {}) } prints: A B AB C
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/1100

          People

          • Assignee:
            Adriaan Moors
            Reporter:
            Adriaan Moors
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development