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

spurious "comparing non-null values .. will always return false" in pattern match

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: Scala 2.10.0-M4
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      
      scala> class A
      defined class A
      
      scala> case object B extends A
      defined module B
      
      scala> (B: A with Product) match { case B => 0 }
      <console>:10: warning: comparing non-null values of types B.type and A with Product using `==' will always yield false
                    (B: A with Product) match { case B => 0 }
                                                     ^
      res2: Int = 0
      
      scala> (B: A with Product) == (B: A)
      res3: Boolean = true
      
      scala> (B: A with Product) == (B: B.type)
      res4: Boolean = true
      

        Activity

        Hide
        Jason Zaugg added a comment -

        Without the pattern matcher:

        class A
        
        case object B extends A
        
        object Test {
          val x1 = (B: A)
        
          println(x1 == B)
          println(B == x1)
        
          val x2 = (B: A with Product)
        
          println(x2 == B)
          println(B == x2) // spurious warning
        }
        
        
        Show
        Jason Zaugg added a comment - Without the pattern matcher: class A case object B extends A object Test { val x1 = (B: A) println(x1 == B) println(B == x1) val x2 = (B: A with Product) println(x2 == B) println(B == x2) // spurious warning }
        Hide
        Jason Zaugg added a comment -

        Things go awry here:

        args = List(Test#20.this.x2#9255)
        underlyingClass(args.head.tpe) = Test#9258 // RefinementClassSymbol
        receiver = object B#14 // ModuleClassSymbol
        receiver isSubClass actual = false
        
        Show
        Jason Zaugg added a comment - Things go awry here: args = List(Test#20.this.x2#9255) underlyingClass(args.head.tpe) = Test#9258 // RefinementClassSymbol receiver = object B#14 // ModuleClassSymbol receiver isSubClass actual = false
        Hide
        Adriaan Moors added a comment -

        Paul, assigning to you since it's not directly pattern matcher related (if I read Jason's comment correctly).

        Show
        Adriaan Moors added a comment - Paul, assigning to you since it's not directly pattern matcher related (if I read Jason's comment correctly).
        Hide
        Jason Zaugg added a comment -

        Yep, pattern matcher isn't culpable.

        I should have noted that receiver.tpe <:< actual.tpe = true, but things seem a bit roundabout, and I have a feeling this check is pretty subtle, so I'm not sure if that's right way to go.

        Show
        Jason Zaugg added a comment - Yep, pattern matcher isn't culpable. I should have noted that receiver.tpe <:< actual.tpe = true , but things seem a bit roundabout, and I have a feeling this check is pretty subtle, so I'm not sure if that's right way to go.
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/800
        Hide
        Seth Tisue added a comment -

        this bit me (well, toothlessly, since it's just a warning) in M4. delighted to find a fix already in place for M5. thanks!

        Show
        Seth Tisue added a comment - this bit me (well, toothlessly, since it's just a warning) in M4. delighted to find a fix already in place for M5. thanks!

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Jason Zaugg
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development