Skip to content

Commit ad2bb89

Browse files
authored
Merge pull request #2364 from dotty-staging/fix-#2360
Fix #2360: Fix inlined module ref.
2 parents c180052 + f7b9bec commit ad2bb89

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,14 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
409409
var lastSelf: Symbol = NoSymbol
410410
var lastLevel: Int = 0
411411
for ((level, selfSym) <- sortedProxies) {
412+
lazy val rhsClsSym = selfSym.info.widenDealias.classSymbol
412413
val rhs =
413-
if (!lastSelf.exists)
414-
prefix
415-
else
414+
if (lastSelf.exists)
416415
untpd.Select(ref(lastSelf), OuterSelectName(EmptyTermName, lastLevel - level)).withType(selfSym.info)
416+
else if (rhsClsSym.is(Module))
417+
ref(rhsClsSym.sourceModule)
418+
else
419+
prefix
417420
bindingsBuf += ValDef(selfSym.asTerm, rhs)
418421
lastSelf = selfSym
419422
lastLevel = level

tests/run/i2360.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42

tests/run/i2360.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
import Foo._
5+
println(foo)
6+
}
7+
}
8+
9+
object Foo extends Bar {
10+
inline def foo: Int = bar
11+
}
12+
13+
class Bar {
14+
def bar = 42
15+
}

0 commit comments

Comments
 (0)