Details

      Description

      ticket/5082 ~/code/scala2 scala29
      Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> case class Y(final var x: Int, final private var y: String, final val z1: Boolean, final private val z2: Any)
      defined class Y
      
      scala> def x = Y.unapply(null)
      x: Option[(Int, String, Boolean, Any)]
      
      scala> ticket/5082 ~/code/scala2 scala-hash v2.10.0
      [info] v2.10.0 => /Users/jason/usr/scala-v2.10.0-0-g18481ce
      Welcome to Scala version 2.10.0-20121205-112020-18481cef9b (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> case class Y(final var x: Int, final private var y: String, final val z1: Boolean, final private val z2: Any)
      defined class Y
      
      scala> def x = Y.unapply(null)
      x: Option[(Int, Boolean, String, Any)]
      
      scala> val Y(a, b, c, d) = Y(0, "", true, new {})
      a: Int = 0
      b: String = ""
      c: Boolean = true
      d: Any = $anon$1@56801919
      
      scala> Y.unapply(Y(0, "", true, new {}))
      res0: Option[(Int, Boolean, String, Any)] = Some((0,true,,$anon$1@2eac0b4))
      

      See also SI-5082. My proposed patch for it happens to reverse this regression.

      Pattern matching, which bypasses the synthesized `unapply` method seems, superficially, to be immune. I seem to remember some code in there that corrected for out-of-order case accessors, but I can't find it. It does use caseAccessors when producing counter-examples, which may be subject to this bug, too.

        Activity

        Hide
        Jason Zaugg added a comment -
              override protected def tupleSel(binder: Symbol)(i: Int): Tree = { import CODE._
                // caseFieldAccessors is messed up after typers (reversed, names mangled for non-public fields)
                // TODO: figure out why...
                val accessors = binder.caseFieldAccessors
                // luckily, the constrParamAccessors are still sorted properly, so sort the field-accessors using them
                // (need to undo name-mangling, including the sneaky trailing whitespace)
                val constrParamAccessors = binder.constrParamAccessors
        
        Show
        Jason Zaugg added a comment - override protected def tupleSel(binder: Symbol)(i: Int): Tree = { import CODE._ // caseFieldAccessors is messed up after typers (reversed, names mangled for non-public fields) // TODO: figure out why... val accessors = binder.caseFieldAccessors // luckily, the constrParamAccessors are still sorted properly, so sort the field-accessors using them // (need to undo name-mangling, including the sneaky trailing whitespace) val constrParamAccessors = binder.constrParamAccessors
        Hide
        Jason Zaugg added a comment -
            val originalAccessors = clazz.caseFieldAccessors
            // private ones will have been renamed -- make sure they are entered
            // in the original order.
            def accessors = clazz.caseFieldAccessors sortBy { acc =>
              originalAccessors indexWhere { orig =>
                (acc.name == orig.name) || (acc.name startsWith (orig.name append "$"))
              }
            }
        
        Show
        Jason Zaugg added a comment - val originalAccessors = clazz.caseFieldAccessors // private ones will have been renamed -- make sure they are entered // in the original order. def accessors = clazz.caseFieldAccessors sortBy { acc => originalAccessors indexWhere { orig => (acc.name == orig.name) || (acc.name startsWith (orig.name append "$")) } }
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/1997

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development