Skip to content

Commit 0c63736

Browse files
committed
Fix infinite recursion when creating extension methods
Phase ExtensionMethods creates new symbols for extension methods and then installs these symbols into the companion object of a value class. It's important that the creation of these symbols is done in the phase ExtensionMethods itself, and not in the next phase, as was done before. If we do it in the next phase, we need the owner at the next phase and with the new scheme of computeDenot that owner might be forced, leading to an infinite cycle.
1 parent d86372f commit 0c63736

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
5454
ctx.atPhase(thisTransformer.next) { implicit ctx =>
5555
// In Scala 2, extension methods are added before pickling so we should
5656
// not generate them again.
57-
if (!(origClass is Scala2x)) {
57+
if (!(origClass is Scala2x)) ctx.atPhase(thisTransformer) { implicit ctx =>
5858
for (decl <- origClass.classInfo.decls) {
5959
if (isMethodWithExtension(decl))
6060
decls1.enter(createExtensionMethod(decl, ref.symbol))
@@ -91,7 +91,6 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
9191
else NoSymbol
9292

9393
private def createExtensionMethod(imeth: Symbol, staticClass: Symbol)(implicit ctx: Context): TermSymbol = {
94-
assert(ctx.phase == thisTransformer.next)
9594
val extensionName = extensionNames(imeth).head.toTermName
9695
val extensionMeth = ctx.newSymbol(staticClass, extensionName,
9796
imeth.flags | Final &~ (Override | Protected | AbsOverride),

0 commit comments

Comments
 (0)