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

Universal traits shouldn't allow nested objects #6408

Closed
scabug opened this issue Sep 19, 2012 · 5 comments
Closed

Universal traits shouldn't allow nested objects #6408

scabug opened this issue Sep 19, 2012 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 19, 2012

According to SIP-15, "Universal traits may have neither fields nor initialization statements." Nested objects are effectively both.

trait U extends Any {
  def x: Int
  object X {
    lazy val y = { println("x: " + x); x }
    var yy = x
  }
}

class V(val x: Int) extends AnyVal with U

object W {
  def main(args: Array[String]) {
    val v = new V(3)
    val z = v.X.y
    v.X.yy = 30
    val z2 = v.X.y
    val v2 = new V(4)
    v2.X.yy = 31
    println(z)
    println(z2)
    println(v.X.yy)
    println(v2.X.yy)
  }
}

Output:

x: 3
x: 3
3
3
3
4

Output without extends AnyVal:

x: 3
3
3
30
31

I'm not sure if nested classes and traits should be excluded as well, but it might be safer to start by excluding them.

@scabug
Copy link
Author

scabug commented Sep 19, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6408?orig=1
Reporter: @harrah
Affected Versions: 2.10.0
Other Milestones: 2.10.0

@scabug
Copy link
Author

scabug commented Sep 19, 2012

@jsuereth said:
hey martin, throwing one your way, please punt to whoever is appropriate, thanks!

@scabug
Copy link
Author

scabug commented Sep 22, 2012

@odersky said:
scala/scala#1366

@scabug
Copy link
Author

scabug commented Sep 29, 2012

@odersky said:
Greg has taken this one over.

@scabug
Copy link
Author

scabug commented Oct 3, 2012

@gkossakowski said:
Fixed in scala/scala#1443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants