Skip to content

Commit b56c035

Browse files
committed
Fix: handle accesses to private aliases from inlined code
Dealias them and try again.
1 parent 62fc304 commit b56c035

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import ErrorReporting.errorTree
2626
import collection.mutable
2727
import transform.TypeUtils._
2828
import reporting.trace
29+
import util.Positions.Position
2930

3031
object Inliner {
3132
import tpd._
@@ -549,6 +550,18 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
549550

550551
var retainedInlineables = Set[Symbol]()
551552

553+
override def ensureAccessible(tpe: Type, superAccess: Boolean, pos: Position)(implicit ctx: Context): Type = {
554+
tpe match {
555+
case tpe @ TypeRef(pre, _) if !tpe.symbol.isAccessibleFrom(pre, superAccess) =>
556+
tpe.info match {
557+
case TypeAlias(alias) => return ensureAccessible(alias, superAccess, pos)
558+
case _ =>
559+
}
560+
case _ =>
561+
}
562+
super.ensureAccessible(tpe, superAccess, pos)
563+
}
564+
552565
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context) =
553566
tree.asInstanceOf[tpd.Tree] match {
554567
case InlineableArg(rhs) => inlining.println(i"inline arg $tree -> $rhs"); rhs

tests/pos/inlineAccesses.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
trait T {
2+
object O
3+
}
4+
5+
class C {
6+
private type T = C
7+
private var x = 0
8+
9+
inline def f = {
10+
x += 1
11+
x = x + 1
12+
x
13+
}
14+
inline def dup = new T
15+
}
16+
17+
object Test {
18+
19+
val c = new C
20+
c.f
21+
c.dup
22+
}

0 commit comments

Comments
 (0)