Skip to content

private[this] constructor var shadows itself #6880

Closed
@scabug

Description

@scabug
class Example(private[this] var con1: Int, private var con2: Int) {
  private[this] var field1: Int = -3
  private var field2: Int = -3

  println("[constructor, before] " + ((con1, con2, field1, field2)))
  con1 = 75
  con2 = 75
  field1 = 75
  field2 = 75
  println("[constructor, after] " + ((con1, con2, field1, field2)))

  def xValue = ((con1, con2, field1, field2))
}

object Test {
  def main(args: Array[String]) {
    val example = new Example(-3, -3)
    println("[post-constructor] " + example.xValue) // prints -3, expected 0.
  }
}

This prints:

[constructor, before] (-3,-3,-3,-3)
[constructor, after] (75,75,75,75)
[post-constructor] (-3,75,75,75)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions