Skip to content

Handle inline super prefix bindings #13649

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
Oct 5, 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/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()
}