Skip to content
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

Fix inlining when outer select is needed from inline call prefix #15327

Merged
merged 1 commit into from
Jun 1, 2022
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
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ object TypeOps:

/** Map a `C.this` type to the right prefix. If the prefix is unstable, and
* the current variance is <= 0, return a range.
* @param pre The prefix
* @param cls The class in which the `C.this` type occurs
* @param thiscls The prefix `C` of the `C.this` type.
*/
def toPrefix(pre: Type, cls: Symbol, thiscls: ClassSymbol): Type = /*>|>*/ trace.conditionally(track, s"toPrefix($pre, $cls, $thiscls)", show = true) /*<|<*/ {
if ((pre eq NoType) || (pre eq NoPrefix) || (cls is PackageClass))
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class ExplicitSelf extends MiniPhase {
override def description: String = ExplicitSelf.description

private def needsCast(tree: RefTree, cls: ClassSymbol)(using Context) =
!cls.is(Package) && cls.givenSelfType.exists && !cls.derivesFrom(tree.symbol.owner)
!cls.is(Package)
&& cls.givenSelfType.exists
&& tree.symbol.exists
&& !cls.derivesFrom(tree.symbol.owner)

private def castQualifier(tree: RefTree, cls: ClassSymbol, thiz: Tree)(using Context) =
val selfType = cls.classInfo.selfType
Expand Down
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
else if lastSelf.exists then
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
else
inlineCallPrefix match
case Super(_, _) => This(rhsClsSym.asClass)
case _ => inlineCallPrefix
val pre = inlineCallPrefix match
case Super(qual, _) => qual
case pre => pre
val preLevel = inlinedMethod.owner.ownersIterator.length
if preLevel > level then pre.outerSelect(preLevel - level, selfSym.info)
else pre

val binding = accountForOpaques(
ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span))
bindingsBuf += binding
Expand Down
15 changes: 15 additions & 0 deletions tests/run/i15317.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Outer {
val outer = 1
object Inner {
def forwarder: Int = inlined
transparent inline def inlined: Int = outer
}
object Inner2 {
def forwarder: Int = inlined
inline def inlined: Int = outer
}
}

@main def Test =
assert((new Outer).Inner.forwarder == 1)
assert((new Outer).Inner2.forwarder == 1)