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

this qualified field masked by argument #3194

Closed
scabug opened this issue Mar 19, 2010 · 9 comments · Fixed by scala/scala#8558
Closed

this qualified field masked by argument #3194

scabug opened this issue Mar 19, 2010 · 9 comments · Fixed by scala/scala#8558
Assignees

Comments

@scabug
Copy link

scabug commented Mar 19, 2010

I can't say definitively this is a bug. But I think it should be. There is only one thing which "this.x" can mean. It looks to me like this could be implemented with some extra logic in typedAssign.

class A(var x: Int)
class B(x: Int) extends A(x) { def update(z: Int) = this.x = z }
a.scala:2: error: reassignment to val
class B(x: Int) extends A(x) { def update(z: Int) = this.x = z }
                                                           ^
one error found

I would expect it to work like the common situation (common in java anyway) where one does:

def f(x: Int) = this.x = x
@scabug
Copy link
Author

scabug commented Mar 19, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3194?orig=1
Reporter: @paulp

@scabug
Copy link
Author

scabug commented Mar 23, 2010

@odersky said:
I think this is fundamentally a duplicate of another ticket, but I can't find it right now. The problem is that the constructor parameter does get modelled as a private[this] field. For the duplicate I decided that this should wait until after 2.8 since changing it now would be too risky.

@scabug
Copy link
Author

scabug commented Mar 23, 2010

@paulp said:
Replying to [comment:3 odersky]:

I think this is fundamentally a duplicate of another ticket, but I can't find it right now. The problem is that the constructor parameter does get modelled as a private[this] field. For the duplicate I decided that this should wait until after 2.8 since changing it now would be too risky.

That's fine - there's no ticket I open these days intending it to be addressed before 2.8 unless it involves planes falling out of the sky. I only open them so I don't forget.

@scabug
Copy link
Author

scabug commented Sep 22, 2010

@paulp said:
See #3861 for a related issue and a workaround to this one. (TL/DR: give B a self-type of A.)

@scabug
Copy link
Author

scabug commented Jan 31, 2011

@paulp said:
Here is another related issue. There does not seem to be any way to get this to compile without changing the name of the parameter in Foo.

trait Settings {
  type T = Int
  def f: T = 5
}

class Bar(val settings: Settings) { }

class Foo(settings: Settings) extends Bar(settings) {
  def g = settings.f
}
a.scala:9: error: private value settings escapes its defining scope as part of type Foo.this.settings.T
  def g = settings.f
      ^
one error found

@scabug
Copy link
Author

scabug commented Feb 19, 2011

@paulp said:
Replying to [comment:5 extempore]:

See #3861 for a related issue and a workaround to this one. (TL/DR: give B a self-type of A.)

Now that #3861 is fixed, as one might suppose, the workaround no longer works around.

// This code compiles in 2.8.1 but not since whenever SI-3861 was fixed
// (tested at r24303.)
class A(var x: Int)
class B(x: Int) extends A(x) {
  self: A =>

  def update(z: Int) = this.x = z
}

@scabug
Copy link
Author

scabug commented Jun 18, 2011

@paulp said:
See also #4606.

@scabug
Copy link
Author

scabug commented Jul 4, 2011

@paulp said:
See also #4762.

@som-snytt
Copy link

The limited fix is in the linked PR. We are safely past 2.8 final, so the risk of the change is deemed acceptable. There are variants mentioned here that are worth revisiting.

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

Successfully merging a pull request may close this issue.

3 participants