Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"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 #5720

Closed
scabug opened this issue Apr 29, 2012 · 9 comments

Comments

@scabug
Copy link

commented Apr 29, 2012

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:
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:

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)

@scabug

This comment has been minimized.

Copy link
Author

commented Apr 29, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5720?orig=1
Reporter: @OlegYch
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@paulp said:
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()
}
@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@som-snytt said (edited on May 3, 2012 4:20:13 AM UTC):
I commented on #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.

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@paulp said:
Hang onto that ball! You're on exactly the right track.

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@som-snytt said:
scala/scala#468
makes the example work (and #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.

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@paulp said:
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.

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@som-snytt said:
Yes, that's the flag I was talking about.

@scabug

This comment has been minimized.

Copy link
Author

commented May 3, 2012

@som-snytt said:
You didn't hear me say, D'oh!

@scabug

This comment has been minimized.

Copy link
Author

commented May 5, 2012

@som-snytt said:
aabe71f989f023d64b6c52680485e4cacb4e88b9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.