Skip to content

Commit f49b95f

Browse files
authored
Merge pull request #9121 from dotty-staging/fix-static-cycle
Avoid cycle between Java static class and outer class
2 parents c183e1f + 9396ad8 commit f49b95f

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,10 @@ object SymDenotations {
22022202
if (companion.isClass && !isAbsent(canForce = false) && !companion.isAbsent(canForce = false))
22032203
myCompanion = companion
22042204

2205-
override def registeredCompanion(implicit ctx: Context) = { ensureCompleted(); myCompanion }
2205+
override def registeredCompanion(implicit ctx: Context) =
2206+
if !myCompanion.exists then
2207+
ensureCompleted()
2208+
myCompanion
22062209
override def registeredCompanion_=(c: Symbol) = { myCompanion = c }
22072210

22082211
private var myNestingLevel = -1

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ class ClassfileParser(
180180

181181
for (i <- 0 until in.nextChar) parseMember(method = false)
182182
for (i <- 0 until in.nextChar) parseMember(method = true)
183+
184+
classRoot.registerCompanion(moduleRoot.symbol)
185+
moduleRoot.registerCompanion(classRoot.symbol)
186+
187+
setClassInfo(moduleRoot, staticInfo, fromScala2 = false)
188+
183189
classInfo = parseAttributes(classRoot.symbol, classInfo)
184190
if (isAnnotation)
185191
// classInfo must be a TempClassInfoType and not a TempPolyType,
186192
// because Java annotations cannot have type parameters.
187193
addAnnotationConstructor(classInfo.asInstanceOf[TempClassInfoType])
188194

189-
classRoot.registerCompanion(moduleRoot.symbol)
190-
moduleRoot.registerCompanion(classRoot.symbol)
191-
192195
setClassInfo(classRoot, classInfo, fromScala2 = false)
193-
setClassInfo(moduleRoot, staticInfo, fromScala2 = false)
194196
}
195197
else if (result == Some(NoEmbedded))
196198
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
@@ -916,7 +918,7 @@ class ClassfileParser(
916918
}
917919

918920
/** Return the class symbol for `entry`. It looks it up in its outer class.
919-
* Forces all outer class symbols to be completed.
921+
* This might force outer class symbols.
920922
*/
921923
def classSymbol(entry: InnerClassEntry)(implicit ctx: Context): Symbol = {
922924
def getMember(sym: Symbol, name: Name)(implicit ctx: Context): Symbol =
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Foo<T extends Foo<T>> {}
2+
3+
public class A_1 extends Foo<A_1.InnerClass> {
4+
public static class InnerClass extends Foo<A_1.InnerClass> {}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object B {
2+
val a = new A_1
3+
}

0 commit comments

Comments
 (0)