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

Late Initialization of Vals #399

Closed
scabug opened this issue Jan 22, 2008 · 7 comments
Closed

Late Initialization of Vals #399

scabug opened this issue Jan 22, 2008 · 7 comments

Comments

@scabug
Copy link

scabug commented Jan 22, 2008

I would expect that vals of an class/object are either not accessible before their declaration (=> compile-error) or they should already be initialized. (see attached example)

@scabug
Copy link
Author

scabug commented Jan 22, 2008

Imported From: https://issues.scala-lang.org/browse/SI-399?orig=1
Reporter: @michael-nischt
Attachments:

  • Test.scala (created on Jan 22, 2008 8:12:03 AM UTC, 253 bytes)

@scabug
Copy link
Author

scabug commented Jan 22, 2008

@michael-nischt said:
Code Example

@scabug
Copy link
Author

scabug commented Jan 22, 2008

Geoffrey Alan Washburn (washburn) said:
This is the expected behavior. Use "lazy val" if would like to have your desired behavior.

@scabug
Copy link
Author

scabug commented Jan 22, 2008

@michael-nischt said:
Replying to [comment:1 washburn]:

This is the expected behavior. Use "lazy val" if would like to have your desired behavior.

Really, I mean this is a source of unnecessary bugs. Futhermore it breaks the contract of vals, because the value changes from the default to the assigned.

Actually, I would strongly recommend to make it result in a compile error 'undeclared', as it isn't a that time.

@scabug
Copy link
Author

scabug commented Jan 23, 2008

Geoffrey Alan Washburn (washburn) said:
Marking the use undeclared would not solve the problem, because you could still write the following and observe this

class Foo {
  println ( this.foo )
  val foo = 1
}

It is less than ideal, but we have discussed the problem, and I am told that attempts to fix this have been made in the past, and given the limitations of the JVM, they were all worse.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.7.0 deleted

@SethTisue
Copy link
Member

SethTisue commented Mar 22, 2019

this is the oldest ticket on this, afaict.

there are many others, so anyone wanting to find all of the discussion on this over the years has some link-chasing to do, e.g. to #4152 and many other linked or transitively linked tickets, mailing list discussions, etc

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