Skip to content

Commit 27f4a94

Browse files
authored
Avoid stackoverflow in ExplicitOuter (#16381)
When transforming a class at ExplicitOuter we create outer accessors for it. The newSymbol call to do this takes place at phase ExplicitOuter + 1, but its arguments need to be evaluated at phase ExplicitOuter. This was not true for the nestingLevel argument, which demanded the denotation of the class at phase ExplicitOuter + 1, thus leading to the SO. Interestingly, the same path is not taken if the class has all abstract members defined or is declared abstract. It's only in the error case that I could reproduce the SO. Fixes #16343
2 parents bf83641 + e92dd4d commit 27f4a94

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ object ExplicitOuter {
176176
if prefix == NoPrefix then outerCls.typeRef.appliedTo(outerCls.typeParams.map(_ => TypeBounds.empty))
177177
else prefix.widen)
178178
val info = if (flags.is(Method)) ExprType(target) else target
179+
val currentNestingLevel = ctx.nestingLevel
179180
atPhaseNoEarlier(explicitOuterPhase.next) { // outer accessors are entered at explicitOuter + 1, should not be defined before.
180-
newSymbol(owner, name, SyntheticArtifact | flags, info, coord = cls.coord)
181+
newSymbol(owner, name, SyntheticArtifact | flags, info, coord = cls.coord, nestingLevel = currentNestingLevel)
181182
}
182183
}
183184

tests/neg/i16343.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Issue16343:
2+
class MyWorker extends javax.swing.SwingWorker[Unit, Unit] // error

0 commit comments

Comments
 (0)