Skip to content

Commit

Permalink
Handle inline super prefix bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki authored and olsdavis committed Apr 4, 2022
1 parent 502d511 commit 4465524
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
var lastSelf: Symbol = NoSymbol
var lastLevel: Int = 0
for ((level, selfSym) <- sortedProxies) {
lazy val rhsClsSym = selfSym.info.widenDealias.classSymbol
val rhs = selfSym.info.dealias match
case info: TermRef
if info.isStable && (lastSelf.exists || isPureExpr(inlineCallPrefix)) =>
Expand All @@ -562,7 +561,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
else if lastSelf.exists then
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
else
inlineCallPrefix
inlineCallPrefix match
case Super(_, _) => This(rhsClsSym.asClass)
case _ => inlineCallPrefix
val binding = accountForOpaques(
ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span))
bindingsBuf += binding
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i13586.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo:
inline def test(): Unit = this

class Bar extends Foo:
def test(s: String) = super.test()
6 changes: 6 additions & 0 deletions tests/pos/i13586/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted._

object Position {
def withPosition[T](fun: Expr[Unit => T])(using quotes: Quotes, typeOfT: Type[T]): Expr[T] =
'{${fun}.apply(null)}
}
10 changes: 10 additions & 0 deletions tests/pos/i13586/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo {
inline def test(): Unit = {
${ Position.withPosition[Unit]('{ _ => this }) }
}
}

class Bar extends Foo {
def test(s: String) =
super.test()
}

0 comments on commit 4465524

Please sign in to comment.