Skip to content

Fix a potential StackOverflow in recursion detection code #6013

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
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
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ class MissingType(pre: Type, name: Name) extends TypeError {
}
}

class RecursionOverflow(val op: String, details: => String, previous: Throwable, val weight: Int) extends TypeError {
class RecursionOverflow(val op: String, details: => String, val previous: Throwable, val weight: Int) extends TypeError {

def explanation: String = s"$op $details"

private def recursions: List[RecursionOverflow] = {
val nested = previous match {
case previous: RecursionOverflow => previous.recursions
case _ => Nil
import scala.collection.mutable.ListBuffer
val result = ListBuffer.empty[RecursionOverflow]
@annotation.tailrec def loop(throwable: Throwable): List[RecursionOverflow] = throwable match {
case ro: RecursionOverflow =>
result += ro
loop(ro.previous)
case _ => result.toList

}
this :: nested
loop(this)
}

def opsString(rs: List[RecursionOverflow])(implicit ctx: Context): String = {
Expand Down