Skip to content

Inliner doesn't cope with private[this] vars #6213

Closed
@scabug

Description

@scabug

The following change that just got merged:
scala/scala#1095

introduced marking fields accessed by @inline method.

Now, it seems like inliner doesn't cope well with private[this] fields.

Apply the following patch to the test-case:

diff --git a/test/files/pos/inline-access-levels/A_1.scala b/test/files/pos/inline-access-levels/A_1.scala
index 479fe0f..db788cb 100644
--- a/test/files/pos/inline-access-levels/A_1.scala
+++ b/test/files/pos/inline-access-levels/A_1.scala
@@ -3,8 +3,14 @@ package test
 object A {
 
   private var x: Int = 0
+  // translation at bytecode level is different for private[this] so we need to test both
+  private[this] var y: Int = 0
 
   @inline def actOnX(f: Int => Int) = {
     x = f(x)
   }
+
+  @inline def actOnY(f: Int => Int) = {
+    y = f(y)
+  }
 }
diff --git a/test/files/pos/inline-access-levels/Test_2.scala b/test/files/pos/inline-access-levels/Test_2.scala
index 12c9eb5..7c85642 100644
--- a/test/files/pos/inline-access-levels/Test_2.scala
+++ b/test/files/pos/inline-access-levels/Test_2.scala
@@ -3,9 +3,8 @@ package test
 object Test {
 
   def main(args: Array[String]) {
-
     A.actOnX(_ + 1)
-
+    A.actOnY(_ + 2)
   }
 
 }

and now see it fail:

./partest files/pos/inline-access-levels

Testing individual files
testing: [...]/files/pos/inline-access-levels                         [FAILED]
1 of 1 tests failed (elapsed time: 00:00:03)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions