Created
March 20, 2018 10:38
-
-
Save milessabin/5434cef5bb88545237e43f20abf96893 to your computer and use it in GitHub Desktop.
Side-effects are bad, right?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What output does this yield? What should it? (try with either 2.12.x or 2.13.x) | |
// (spoiler: https://github.com/scala/bug/issues/10788) | |
object Test { | |
class Box[T](t: T) { | |
def foo: T = { | |
println("effect") | |
t | |
} | |
} | |
object Box { | |
def apply(x: String): Box[x.type] = new Box[x.type](x) | |
} | |
def main(args: Array[String]): Unit = { | |
val bar = Box("foo").foo | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment