Skip to content

Commit 2368fb4

Browse files
committed
Fix: handle accesses to private aliases from inlined code
Dealias them and try again.
1 parent bde27bf commit 2368fb4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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

+13
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._
@@ -538,6 +539,18 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
538539

539540
var retainedInlineables = Set[Symbol]()
540541

542+
override def ensureAccessible(tpe: Type, superAccess: Boolean, pos: Position)(implicit ctx: Context): Type = {
543+
tpe match {
544+
case tpe @ TypeRef(pre, _) if !tpe.symbol.isAccessibleFrom(pre, superAccess) =>
545+
tpe.info match {
546+
case TypeAlias(alias) => return ensureAccessible(alias, superAccess, pos)
547+
case _ =>
548+
}
549+
case _ =>
550+
}
551+
super.ensureAccessible(tpe, superAccess, pos)
552+
}
553+
541554
override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context) =
542555
tree.asInstanceOf[tpd.Tree] match {
543556
case InlineableArg(rhs) => inlining.println(i"inline arg $tree -> $rhs"); rhs

tests/pos/inlineAccesses.scala

+22
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)