Skip to content

Avoid cycle between Java static class and outer class #9121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,10 @@ object SymDenotations {
if (companion.isClass && !isAbsent(canForce = false) && !companion.isAbsent(canForce = false))
myCompanion = companion

override def registeredCompanion(implicit ctx: Context) = { ensureCompleted(); myCompanion }
override def registeredCompanion(implicit ctx: Context) =
if !myCompanion.exists then
ensureCompleted()
myCompanion
override def registeredCompanion_=(c: Symbol) = { myCompanion = c }

private var myNestingLevel = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,19 @@ class ClassfileParser(

for (i <- 0 until in.nextChar) parseMember(method = false)
for (i <- 0 until in.nextChar) parseMember(method = true)

classRoot.registerCompanion(moduleRoot.symbol)
moduleRoot.registerCompanion(classRoot.symbol)

setClassInfo(moduleRoot, staticInfo, fromScala2 = false)

classInfo = parseAttributes(classRoot.symbol, classInfo)
if (isAnnotation)
// classInfo must be a TempClassInfoType and not a TempPolyType,
// because Java annotations cannot have type parameters.
addAnnotationConstructor(classInfo.asInstanceOf[TempClassInfoType])

classRoot.registerCompanion(moduleRoot.symbol)
moduleRoot.registerCompanion(classRoot.symbol)

setClassInfo(classRoot, classInfo, fromScala2 = false)
setClassInfo(moduleRoot, staticInfo, fromScala2 = false)
}
else if (result == Some(NoEmbedded))
for (sym <- List(moduleRoot.sourceModule, moduleRoot.symbol, classRoot.symbol)) {
Expand Down Expand Up @@ -916,7 +918,7 @@ class ClassfileParser(
}

/** Return the class symbol for `entry`. It looks it up in its outer class.
* Forces all outer class symbols to be completed.
* This might force outer class symbols.
*/
def classSymbol(entry: InnerClassEntry)(implicit ctx: Context): Symbol = {
def getMember(sym: Symbol, name: Name)(implicit ctx: Context): Symbol =
Expand Down
5 changes: 5 additions & 0 deletions tests/pos-java-interop-separate/static-cycle/A_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Foo<T extends Foo<T>> {}

public class A_1 extends Foo<A_1.InnerClass> {
public static class InnerClass extends Foo<A_1.InnerClass> {}
}
3 changes: 3 additions & 0 deletions tests/pos-java-interop-separate/static-cycle/B_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object B {
val a = new A_1
}