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

"Trying to access the this of another class" or "symbol value x$4$1 does not exist" when compiling code involving anonymous functions, multiple parameter lists and default arguments

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M3, Scala 2.10.0
    • Component/s: None
    • Labels:
      None

      Description

      this code

      class C {
        case class M(currentUser: String)(message: String = "")
        def model = Option(M("")()).getOrElse(M("")()).copy(currentUser = "")()
      }
      

      leads to Error: symbol value x$4$1 does not exist in C.model in 2.9.1 and 2.9.2
      or something like the following in later versions
      uncaught exception during compilation: java.lang.AssertionError
      java.lang.AssertionError: assertion failed:
      while compiling: <console>
      current phase: icode
      library version: version 2.10.0-20120428-143539-774cd4f87b
      compiler version: version 2.10.0-20120428-143539-774cd4f87b
      reconstructed args:

      Trying to access the this of another class: tree.symbol = class $read$$iw$$iw$C,
      ctx.clazz.symbol = anonymous class $read$$iw$$iw$C$$anonfun$1 compilation unit:
      <console>
      at scala.Predef$.assert(Predef.scala:182)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$bac
      kend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:944)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(Ge
      nICode.scala:1151)

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          Somewhat minimized; does seem to require a lot of elements working in concert, but I eliminated case classes, nested classes, and copy methods. Appears to key on anonymous functions nested in anonymous functions.

          class M(x0: Int = 1)(x1: Int = 1) {
            def g(x2: Int = 1) = ()
          }
          
          object Test {
            ((null: Option[M]) getOrElse new M()()).g()
          }
          
          Show
          Paul Phillips added a comment - Somewhat minimized; does seem to require a lot of elements working in concert, but I eliminated case classes, nested classes, and copy methods. Appears to key on anonymous functions nested in anonymous functions. class M(x0: Int = 1)(x1: Int = 1) { def g(x2: Int = 1) = () } object Test { ((null: Option[M]) getOrElse new M()()).g() }
          Hide
          A. P. Marki added a comment - - edited

          I commented on SI-5727. For this example, when the qual$1 is generated (for qual$1.copy), the x$s in the getOrElse have already been generated with owner model, but ownership is not updated to qual$1.

          That's why uncurry (in making the Function) fails to update owner. And that's why lambda lift thinks the x$s are free.

          I'm about to see where to fix TNA (transformNamedAppl), and if that's it, I'll submit a pull, otherwise bounce the ball back.

          Show
          A. P. Marki added a comment - - edited I commented on SI-5727 . For this example, when the qual$1 is generated (for qual$1.copy), the x$s in the getOrElse have already been generated with owner model, but ownership is not updated to qual$1. That's why uncurry (in making the Function) fails to update owner. And that's why lambda lift thinks the x$s are free. I'm about to see where to fix TNA (transformNamedAppl), and if that's it, I'll submit a pull, otherwise bounce the ball back.
          Hide
          Paul Phillips added a comment -

          Hang onto that ball! You're on exactly the right track.

          Show
          Paul Phillips added a comment - Hang onto that ball! You're on exactly the right track.
          Hide
          A. P. Marki added a comment -

          https://github.com/scala/scala/pull/468
          makes the example work (and SI-5727), but I did not yet look for other instances of the bug pattern (failure to change owner). It seems like something worth encapsulating.

          Also, it's probably too "ownerous" [failure to resist pun] to make lambda lift robust against bad ownership; but maybe a debug flag to sanity check it.

          Show
          A. P. Marki added a comment - https://github.com/scala/scala/pull/468 makes the example work (and SI-5727 ), but I did not yet look for other instances of the bug pattern (failure to change owner). It seems like something worth encapsulating. Also, it's probably too "ownerous" [failure to resist pun] to make lambda lift robust against bad ownership; but maybe a debug flag to sanity check it.
          Hide
          Paul Phillips added a comment -

          Awesome, nice job! I forgot to point out (speaking of debug flags) try compiling with -Ycheck:all. I believe this example starts complaining about the owners after uncurry.

          Show
          Paul Phillips added a comment - Awesome, nice job! I forgot to point out (speaking of debug flags) try compiling with -Ycheck:all. I believe this example starts complaining about the owners after uncurry.
          Hide
          A. P. Marki added a comment -

          Yes, that's the flag I was talking about.

          Show
          A. P. Marki added a comment - Yes, that's the flag I was talking about.
          Hide
          A. P. Marki added a comment -

          You didn't hear me say, D'oh!

          Show
          A. P. Marki added a comment - You didn't hear me say, D'oh!
          Hide
          A. P. Marki added a comment -

          aabe71f989f023d64b6c52680485e4cacb4e88b9

          Show
          A. P. Marki added a comment - aabe71f989f023d64b6c52680485e4cacb4e88b9

            People

            • Assignee:
              A. P. Marki
              Reporter:
              Oleg Aleshko
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development