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

This comment has been minimized.

Copy link
Author

@scabug 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

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 19, 2012

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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 22, 2012

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 29, 2012

@odersky said:
Greg has taken this one over.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Oct 3, 2012

@scabug scabug closed this Oct 3, 2012
@scabug scabug added this to the 2.10.0-M7 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.