Skip to content

Side effects incorrectly elided by Erasure's handling of Unit #8666

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

Closed
scabug opened this issue Jun 14, 2014 · 3 comments
Closed

Side effects incorrectly elided by Erasure's handling of Unit #8666

scabug opened this issue Jun 14, 2014 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jun 14, 2014

next code:

object A {
  val init = println("hello")
}

object Main {
  def main(args: Array[String]) {
      val a = A.init
  }
}

produces no output, but "hello" is expected.
This behaviour was observed when trying code described here http://stackoverflow.com/questions/24221601/scala-object-initialization

@scabug
Copy link
Author

scabug commented Jun 14, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8666?orig=1
Reporter: Maksym Besida (mbesida)
Affected Versions: 2.10.3
See #5304

@scabug
Copy link
Author

scabug commented Jun 14, 2014

@retronym said:
This relates to #5304, which shows other examples where the object initialization is elided.

This particular instance comes down to:

//src/compiler/scala/tools/nsc/transform/TypeAdaptingTransformer.scala
          case UnitClass  =>
            if (treeInfo isExprSafeToInline tree) REF(BoxedUnit_UNIT)
            else BLOCK(tree, REF(BoxedUnit_UNIT))

isExprSafeToInline is insufficient, we have to check whether the tree is safe to elide.

@SethTisue
Copy link
Member

I added a reference from #5304 to here. closing

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

No branches or pull requests

3 participants