Skip to content

StackOverflowError when using implicit class compiled with Scala 3 in Scala 2 #13105

@jadenPete

Description

@jadenPete

Reproduction steps

Scala 2 version: 2.13.16
Scala 3 version: 3.6.3

Please let me know if scala/scala3 is a better place to post this.

  1. Compile the following with Scala 3:
package foo

package object bar {
  implicit class EnrichedNumberOption(private val number: Option[Int]) {
    def +(other: Option[Int]): Option[Int] = number.flatMap(number => other.map(number + _))
  }
}
  1. Compile the following with Scala 2:
package foo.bar

object Main {
  None + None
}
  1. Observe the following exception:
java.lang.StackOverflowError
scala.reflect.internal.Symbols$Symbol.isTopLevel(Symbols.scala:1048)
scala.reflect.internal.Symbols$ClassSymbol.associatedFile(Symbols.scala:3442)
scala.reflect.internal.Symbols$Symbol.isCoDefinedWith(Symbols.scala:2346)
scala.reflect.internal.Symbols$Symbol.$anonfun$companionClass$1(Symbols.scala:2385)
scala.reflect.internal.Symbols$Symbol.$anonfun$companionClass$1$adapted(Symbols.scala:2385)
scala.reflect.internal.Symbols$Symbol.filter(Symbols.scala:2061)
scala.reflect.internal.Symbols$Symbol.suchThat(Symbols.scala:2065)
scala.reflect.internal.Symbols$Symbol.companionClass(Symbols.scala:2385)
scala.reflect.internal.Symbols$ModuleClassSymbol.linkedClassOfClass(Symbols.scala:3549)
scala.tools.nsc.typechecker.Infer$Inferencer.isProperSubClassOrObject(Infer.scala:923)
scala.tools.nsc.typechecker.Infer$Inferencer.isProperSubClassOrObject(Infer.scala:923)
scala.tools.nsc.typechecker.Infer$Inferencer.isProperSubClassOrObject(Infer.scala:923)
...

Problem

I'd expect the Scala 2 code to compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions