Skip to content

Use expanded names for inline proxies in traits #11534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/AccessProxies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ abstract class AccessProxies {
trait Insert {
import ast.tpd._

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

def ifNoHost(reference: RefTree)(using Context): Tree = {
Expand Down Expand Up @@ -134,7 +135,7 @@ abstract class AccessProxies {
if (accessorClass.exists) {
if accessorClass.is(Package) then
accessorClass = ctx.owner.topLevelClass
val accessorName = accessorNameKind(accessed.name)
val accessorName = accessorNameOf(accessed.name, accessorClass)
val accessorInfo =
accessed.info.ensureMethodic.asSeenFrom(accessorClass.thisType, accessed.owner)
val accessor = accessorSymbol(accessorClass, accessorName, accessorInfo, accessed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import core.NameKinds._
import core.Symbols._
import core.Flags._
import core.Decorators._
import core.Names.TermName
import MegaPhase.MiniPhase
import config.Printers.transforms

Expand Down Expand Up @@ -51,7 +52,7 @@ class ProtectedAccessors extends MiniPhase {

object Accessors extends AccessProxies {
val insert: Insert = new Insert {
def accessorNameKind = ProtectedAccessorName
def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName = ProtectedAccessorName(name)
def needsAccessor(sym: Symbol)(using Context) = ProtectedAccessors.needsAccessor(sym)

override def ifNoHost(reference: RefTree)(using Context): Tree = {
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Decorators._
import NameKinds._
import StdNames.nme
import Contexts._
import Names.Name
import Names.{Name, TermName}
import NameKinds.{InlineAccessorName, UniqueInlineName}
import NameOps._
import Annotations._
Expand All @@ -40,7 +40,9 @@ object PrepareInlineable {
/** A tree map which inserts accessors for non-public term members accessed from inlined code.
*/
abstract class MakeInlineableMap(val inlineSym: Symbol) extends TreeMap with Insert {
def accessorNameKind: PrefixNameKind = InlineAccessorName
def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName =
val accName = InlineAccessorName(name)
if site.is(Trait) then accName.expandedName(site) else accName

/** A definition needs an accessor if it is private, protected, or qualified private
* and it is not part of the tree that gets inlined. The latter test is implemented
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i10477.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait A:
private def f: Int = 1
inline def g = f
trait B:
private def f: Int = 1
inline def h = f
class C extends A, B


22 changes: 22 additions & 0 deletions tests/pos/i10477/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gopher

import scala.util.Try

def await[F[_],T](f:F[T])(using am:CpsAsyncMonad[F]):T = ???

trait CpsAsyncMonad[F[_]]:

def adoptCallbackStyle[A](source: (Try[A]=>Unit) => Unit): F[A]

trait IChannel[F[_]:CpsAsyncMonad, A]:

def aread:F[A] =
summon[CpsAsyncMonad[F]].adoptCallbackStyle(f => addReader(f))

inline def read: A = await(aread)

def addReader(f: Try[A]=>Unit): Unit


trait IOChannel[F[_]:CpsAsyncMonad,I,O] extends IChannel[F,I] with OChannel[F,O]

15 changes: 15 additions & 0 deletions tests/pos/i10477/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gopher

import scala.util.Try

trait OChannel[F[_]:CpsAsyncMonad, A]:

def awrite(a:A):F[Unit] =
summon[CpsAsyncMonad[F]].adoptCallbackStyle(f =>
addWriter(a, f)
)

inline def write(a:A): Unit = await(awrite(a))

def addWriter(a:A, f: Try[Unit]=>Unit): Unit