Skip to content

Commit e1361cf

Browse files
committed
Don't generate paths with outer accessors to stable references
In that case we can generate directly a reference without going though an inner this proxy and an outer accessor. Fixes #11914.
1 parent eb7b632 commit e1361cf

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
522522
for ((level, selfSym) <- sortedProxies) {
523523
lazy val rhsClsSym = selfSym.info.widenDealias.classSymbol
524524
val rhs =
525-
if (lastSelf.exists)
526-
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
527-
else if (rhsClsSym.is(Module) && rhsClsSym.isStatic)
525+
if lastSelf.exists then
526+
selfSym.info match
527+
case info: TermRef if info.isStable =>
528+
ref(info)
529+
case _ =>
530+
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
531+
else if rhsClsSym.is(Module) && rhsClsSym.isStatic then
528532
ref(rhsClsSym.sourceModule)
529533
else
530534
inlineCallPrefix

tests/run/i11914.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Wrapper[E <: Throwable]:
2+
object syntax:
3+
extension [A <: Matchable](a: E | A)
4+
transparent inline def foreach(f: A => Any): Unit =
5+
a match
6+
case e: E => ()
7+
case a: A => f(a)
8+
9+
def _catch[A](a: => A): E | A =
10+
try a
11+
catch case e: E => e
12+
13+
object throwables extends Wrapper[Throwable]
14+
import throwables.syntax.*
15+
16+
@main def Test(): Unit =
17+
for x <- throwables._catch(1/1) do println(x)

0 commit comments

Comments
 (0)