From 3b0b80d5d5a6db2c97a1c5fe466bbd1361382750 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 1 Oct 2021 16:02:26 +0200 Subject: [PATCH] Handle inline super prefix bindings Fixes #13586 --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 5 +++-- tests/pos/i13586.scala | 5 +++++ tests/pos/i13586/Macro_1.scala | 6 ++++++ tests/pos/i13586/Test_2.scala | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i13586.scala create mode 100644 tests/pos/i13586/Macro_1.scala create mode 100644 tests/pos/i13586/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 5870af1eb7ca..006f963ccbea 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -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)) => @@ -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 diff --git a/tests/pos/i13586.scala b/tests/pos/i13586.scala new file mode 100644 index 000000000000..353660334091 --- /dev/null +++ b/tests/pos/i13586.scala @@ -0,0 +1,5 @@ +class Foo: + inline def test(): Unit = this + +class Bar extends Foo: + def test(s: String) = super.test() diff --git a/tests/pos/i13586/Macro_1.scala b/tests/pos/i13586/Macro_1.scala new file mode 100644 index 000000000000..752ccd906df5 --- /dev/null +++ b/tests/pos/i13586/Macro_1.scala @@ -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)} +} diff --git a/tests/pos/i13586/Test_2.scala b/tests/pos/i13586/Test_2.scala new file mode 100644 index 000000000000..2c7d23a06630 --- /dev/null +++ b/tests/pos/i13586/Test_2.scala @@ -0,0 +1,10 @@ +class Foo { + inline def test(): Unit = { + ${ Position.withPosition[Unit]('{ _ => this }) } + } +} + +class Bar extends Foo { + def test(s: String) = + super.test() +}