Skip to content

Commit 784f55a

Browse files
VladimirNiksmarter
authored andcommitted
Make private accessor in value class not-private.
This is necessary to unbox the value class when accessing it from separate compilation units
1 parent 204182b commit 784f55a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ import Decorators._
1717
import ast.Trees._
1818
import TreeTransforms._
1919
import java.io.File.separatorChar
20+
import ValueClasses._
2021

2122
/** Make private term members that are accessed from another class
2223
* non-private by resetting the Private flag and expanding their name.
2324
*
25+
* Make private accessor in value class not-private. Ihis is necessary to unbox
26+
* the value class when accessing it from separate compilation units
27+
*
2428
* Also, make non-private any private parameter forwarders that forward to an inherited
2529
* public or protected parameter accessor with the same name as the forwarder.
2630
* This is necessary since private methods are not allowed to have the same name
@@ -52,13 +56,18 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
5256
}
5357
}
5458

59+
private def isVCPrivateParamAccessor(d: SymDenotation)(implicit ctx: Context) =
60+
d.isTerm && d.is(PrivateParamAccessor) && isDerivedValueClass(d.owner)
61+
5562
/** Make private terms accessed from different classes non-private.
5663
* Note: this happens also for accesses between class and linked module class.
5764
* If we change the scheme at one point to make static module class computations
5865
* static members of the companion class, we should tighten the condition below.
5966
*/
6067
private def ensurePrivateAccessible(d: SymDenotation)(implicit ctx: Context) =
61-
if (d.is(PrivateTerm) && d.owner != ctx.owner.enclosingClass) {
68+
if (isVCPrivateParamAccessor(d))
69+
d.ensureNotPrivate.installAfter(thisTransform)
70+
else if (d.is(PrivateTerm) && d.owner != ctx.owner.enclosingClass) {
6271
// Paths `p1` and `p2` are similar if they have a common suffix that follows
6372
// possibly different directory paths. That is, their common suffix extends
6473
// in both cases either to the start of the path or to a file separator character.
@@ -94,6 +103,8 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
94103
if sym.is(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name =>
95104
sym.ensureNotPrivate.installAfter(thisTransform)
96105
case _ =>
106+
if (isVCPrivateParamAccessor(sym))
107+
sym.ensureNotPrivate.installAfter(thisTransform)
97108
}
98109
tree
99110
}

0 commit comments

Comments
 (0)