Skip to content

Instantly share code, notes, and snippets.

@lazyval
Last active December 12, 2015 09:29
Show Gist options
  • Select an option

  • Save lazyval/4751726 to your computer and use it in GitHub Desktop.

Select an option

Save lazyval/4751726 to your computer and use it in GitHub Desktop.
Possible bug during object init (or perhaps scala just throws away code that produces only side effects)
object Foo {
val bar = { println("bar"); 42 }
}
object Foo2 {
val bar = { println("bar") }
}
// scala> Foo.bar
// bar
// res0: Int = 42
//
// scala> Foo2.bar
//
// scala>
@lazyval
Copy link
Author

lazyval commented Feb 11, 2013

Expected "bar" to be printed in both cases. Got this behaviour on 2.9.2 final

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