scalameta / mdoc

Typechecked markdown documentation for Scala
https://scalameta.org/mdoc/
Apache License 2.0
394 stars 80 forks source link

Class wrapper causes infinite evaluation/evaluation to fail #853

Open kasiaMarek opened 5 months ago

kasiaMarek commented 5 months ago

For the following code evaluation gets stuck in a loop for Scala 2 and throws StackOverflowException for Scala 3.

class Animal(age: Int)

class Rabbit(age: Int) extends Animal(age):
  val id = Rabbit.tag
  Rabbit.tag += 1
  def getId = id

object Rabbit:
  val basic = Rabbit(0)
  var tag: Int = 0

val peter = Rabbit(2)

Upstream issue: https://github.com/scalameta/metals/issues/4796

The problem is caused by class MdocApp wrapper. Changing it to object MdocApp fixes the issue but causes other issues (with thread deadlocks), full track of this problem in kept in scala-cli repository: https://github.com/VirtusLab/scala-cli/issues/2247.

A proper fix should divide the code so classes/objects etc. are put in an object and rest is put inside of a class. Preferably the solution should be done in such a way it can be shared between mdoc and scala-cli (e.g. the compiler repl).