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

Object initialization bug #9929

Closed
scabug opened this issue Sep 19, 2016 · 2 comments
Closed

Object initialization bug #9929

scabug opened this issue Sep 19, 2016 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 19, 2016

I've found a strange behavior, explained it here: http://stackoverflow.com/questions/39569936/scala-object-initialization-bug

Here is the small example

{code}sealed case class SomeCode(
id: String,
legend: String = "sadsa")

object SomeCode {
println("begin object init")
object First extends SomeCode(id = "First") {println("initializing First")}
object Second extends SomeCode(id = "Second") {println("initializing Second")}
println(SomeCode.First)
}

object Main {

def main(args: Array[String]): Unit = {
SomeCode.First
}

}
{code}

It prints: {code}begin object init
null
initializing First{code}
But if we change First object to this one: {code}object First extends SomeCode(id = "First", "test") {println("initializing First")}{code}
Then the output will be: {code}initializing First{code}

It is ok behavior and I don't understand something, or it is a bug?

@scabug
Copy link
Author

scabug commented Sep 19, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9929?orig=1
Reporter: Vladimir (pronvis)
Affected Versions: 2.11.7
Duplicates #5366

@scabug
Copy link
Author

scabug commented Sep 19, 2016

@som-snytt said:
The linked issue should probably be a "bug" so that it's easier to search for. And because it's a bug.

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