Skip to content

Commit 4d1288e

Browse files
committed
Always make use of stable references in computeThisBindings
1 parent d27fff7 commit 4d1288e

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,17 +516,17 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
516516
var lastLevel: Int = 0
517517
for ((level, selfSym) <- sortedProxies) {
518518
lazy val rhsClsSym = selfSym.info.widenDealias.classSymbol
519-
val rhs =
520-
if lastSelf.exists then
521-
selfSym.info match
522-
case info: TermRef if info.isStable =>
523-
ref(info)
524-
case _ =>
525-
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
526-
else if rhsClsSym.is(Module) && rhsClsSym.isStatic then
527-
ref(rhsClsSym.sourceModule)
528-
else
529-
inlineCallPrefix
519+
val rhs = selfSym.info.dealias match
520+
case info: TermRef if info.isStable =>
521+
ref(info)
522+
case info =>
523+
val rhsClsSym = info.widenDealias.classSymbol
524+
if rhsClsSym.is(Module) && rhsClsSym.isStatic then
525+
ref(rhsClsSym.sourceModule)
526+
else if lastSelf.exists then
527+
ref(lastSelf).outerSelect(lastLevel - level, selfSym.info)
528+
else
529+
inlineCallPrefix
530530
val binding = ValDef(selfSym.asTerm, QuoteUtils.changeOwnerOfTree(rhs, selfSym)).withSpan(selfSym.span)
531531
bindingsBuf += binding
532532
inlining.println(i"proxy at $level: $selfSym = ${bindingsBuf.last}")

tests/run/i11914a.scala

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

0 commit comments

Comments
 (0)