Skip to content

Commit ae2d13a

Browse files
committed
Fix #4357: Avoid cyclic reference when parsing Java classfile
We force all types appearing in the extends clause using `cook` before completing the current class, in B_1.java this means we force `C` before `B_1` is completed, ClassfileLoader#load ends up calling `scalacLinkedClass` which before this commit forced the owner of `C`, causing a cycle.
1 parent 9c83d27 commit ae2d13a

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ object SymDenotations {
990990
*/
991991
private def companionNamed(name: TypeName)(implicit ctx: Context): Symbol =
992992
if (owner.isClass)
993-
owner.info.decl(name).suchThat(_.isCoDefinedWith(symbol)).symbol
993+
owner.unforcedDecls.lookup(name).suchThat(_.isCoDefinedWith(symbol)).symbol
994994
else if (!owner.exists || ctx.compilationUnit == null)
995995
NoSymbol
996996
else if (!ctx.compilationUnit.tpdTree.isEmpty)

tests/pos-java-interop/i4357/B_1.java

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public class B_1 extends A<B_1.C> {
2+
public static class C {};
3+
}
4+
class A<T> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
val b: B_1 = new B_1()
3+
}

0 commit comments

Comments
 (0)