Skip to content

Commit ce30a1c

Browse files
Merge pull request #11534 from dotty-staging/fix-10477
Use expanded names for inline proxies in traits
2 parents 58c77c3 + 4a1a2eb commit ce30a1c

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

compiler/src/dotty/tools/dotc/transform/AccessProxies.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ abstract class AccessProxies {
6868
trait Insert {
6969
import ast.tpd._
7070

71-
def accessorNameKind: ClassifiedNameKind
71+
/** The name of the accessor for definition with given `name` in given `site` */
72+
def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName
7273
def needsAccessor(sym: Symbol)(using Context): Boolean
7374

7475
def ifNoHost(reference: RefTree)(using Context): Tree = {
@@ -134,7 +135,7 @@ abstract class AccessProxies {
134135
if (accessorClass.exists) {
135136
if accessorClass.is(Package) then
136137
accessorClass = ctx.owner.topLevelClass
137-
val accessorName = accessorNameKind(accessed.name)
138+
val accessorName = accessorNameOf(accessed.name, accessorClass)
138139
val accessorInfo =
139140
accessed.info.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner)
140141
val accessor = accessorSymbol(accessorClass, accessorName, accessorInfo, accessed)

compiler/src/dotty/tools/dotc/transform/ProtectedAccessors.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import core.NameKinds._
66
import core.Symbols._
77
import core.Flags._
88
import core.Decorators._
9+
import core.Names.TermName
910
import MegaPhase.MiniPhase
1011
import config.Printers.transforms
1112

@@ -51,7 +52,7 @@ class ProtectedAccessors extends MiniPhase {
5152

5253
object Accessors extends AccessProxies {
5354
val insert: Insert = new Insert {
54-
def accessorNameKind = ProtectedAccessorName
55+
def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName = ProtectedAccessorName(name)
5556
def needsAccessor(sym: Symbol)(using Context) = ProtectedAccessors.needsAccessor(sym)
5657

5758
override def ifNoHost(reference: RefTree)(using Context): Tree = {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Decorators._
1313
import NameKinds._
1414
import StdNames.nme
1515
import Contexts._
16-
import Names.Name
16+
import Names.{Name, TermName}
1717
import NameKinds.{InlineAccessorName, UniqueInlineName}
1818
import NameOps._
1919
import Annotations._
@@ -40,7 +40,9 @@ object PrepareInlineable {
4040
/** A tree map which inserts accessors for non-public term members accessed from inlined code.
4141
*/
4242
abstract class MakeInlineableMap(val inlineSym: Symbol) extends TreeMap with Insert {
43-
def accessorNameKind: PrefixNameKind = InlineAccessorName
43+
def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName =
44+
val accName = InlineAccessorName(name)
45+
if site.is(Trait) then accName.expandedName(site) else accName
4446

4547
/** A definition needs an accessor if it is private, protected, or qualified private
4648
* and it is not part of the tree that gets inlined. The latter test is implemented

tests/pos/i10477.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait A:
2+
private def f: Int = 1
3+
inline def g = f
4+
trait B:
5+
private def f: Int = 1
6+
inline def h = f
7+
class C extends A, B
8+
9+

tests/pos/i10477/A.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package gopher
2+
3+
import scala.util.Try
4+
5+
def await[F[_],T](f:F[T])(using am:CpsAsyncMonad[F]):T = ???
6+
7+
trait CpsAsyncMonad[F[_]]:
8+
9+
def adoptCallbackStyle[A](source: (Try[A]=>Unit) => Unit): F[A]
10+
11+
trait IChannel[F[_]:CpsAsyncMonad, A]:
12+
13+
def aread:F[A] =
14+
summon[CpsAsyncMonad[F]].adoptCallbackStyle(f => addReader(f))
15+
16+
inline def read: A = await(aread)
17+
18+
def addReader(f: Try[A]=>Unit): Unit
19+
20+
21+
trait IOChannel[F[_]:CpsAsyncMonad,I,O] extends IChannel[F,I] with OChannel[F,O]
22+

tests/pos/i10477/Test.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package gopher
2+
3+
import scala.util.Try
4+
5+
trait OChannel[F[_]:CpsAsyncMonad, A]:
6+
7+
def awrite(a:A):F[Unit] =
8+
summon[CpsAsyncMonad[F]].adoptCallbackStyle(f =>
9+
addWriter(a, f)
10+
)
11+
12+
inline def write(a:A): Unit = await(awrite(a))
13+
14+
def addWriter(a:A, f: Try[Unit]=>Unit): Unit
15+

0 commit comments

Comments
 (0)