Skip to content

Commit 3b0b80d

Browse files
committed
Handle inline super prefix bindings
Fixes #13586
1 parent fe24fd3 commit 3b0b80d

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
548548
var lastSelf: Symbol = NoSymbol
549549
var lastLevel: Int = 0
550550
for ((level, selfSym) <- sortedProxies) {
551-
lazy val rhsClsSym = selfSym.info.widenDealias.classSymbol
552551
val rhs = selfSym.info.dealias match
553552
case info: TermRef
554553
if info.isStable && (lastSelf.exists || isPureExpr(inlineCallPrefix)) =>
@@ -562,7 +561,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
562561
else if lastSelf.exists then
563562
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
564563
else
565-
inlineCallPrefix
564+
inlineCallPrefix match
565+
case Super(_, _) => This(rhsClsSym.asClass)
566+
case _ => inlineCallPrefix
566567
val binding = accountForOpaques(
567568
ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span))
568569
bindingsBuf += binding

tests/pos/i13586.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo:
2+
inline def test(): Unit = this
3+
4+
class Bar extends Foo:
5+
def test(s: String) = super.test()

tests/pos/i13586/Macro_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.quoted._
2+
3+
object Position {
4+
def withPosition[T](fun: Expr[Unit => T])(using quotes: Quotes, typeOfT: Type[T]): Expr[T] =
5+
'{${fun}.apply(null)}
6+
}

tests/pos/i13586/Test_2.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Foo {
2+
inline def test(): Unit = {
3+
${ Position.withPosition[Unit]('{ _ => this }) }
4+
}
5+
}
6+
7+
class Bar extends Foo {
8+
def test(s: String) =
9+
super.test()
10+
}

0 commit comments

Comments
 (0)