scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Scaladoc removes indentation of first line, making code incorrect #21429

Closed JD557 closed 2 weeks ago

JD557 commented 1 month ago

Compiler version

3.5.0

Minimized code

See for example https://github.com/scala/scala3/blob/5101daf9f454c23898ec205894a1c97025f39515/docs/_docs/reference/experimental/typeclasses.md?plain=1#L46-L80

or

https://github.com/scala/scala3/blob/5101daf9f454c23898ec205894a1c97025f39515/docs/_docs/reference/experimental/typeclasses.md?plain=1#L135-L144

Output

imagem

Which is copied as:

trait Ord:
    type Self

  trait SemiGroup:
    type Self
    extension (x: Self) def combine(y: Self): Self

  trait Monoid extends SemiGroup:
    def unit: Self
  object Monoid:
    def unit[M](using m: Monoid { type Self = M}): M

  trait Functor:
    type Self[A]
    extension [A](x: Self[A]) def map[B](f: A => B): Self[B]

  trait Monad extends Functor:
    def pure[A](x: A): Self[A]
    extension [A](x: Self[A])
      def flatMap[B](f: A => Self[B]): Self[B]
      def map[B](f: A => B) = x.flatMap(f `andThen` pure)

  def reduce[A: Monoid](xs: List[A]): A =
    xs.foldLeft(Monoid.unit)(_ `combine` _)

  trait ParserCombinator:
    type Self
    type Input
    type Result
    extension (self: Self)
      def parse(input: Input): Option[Result] = ...

  def combine[A: ParserCombinator, B: ParserCombinator { type Input = A.Input }] = ...

or

imagem

which is copied as

given Int is Ord ...
  given Int is Monoid ...

  type Reader = [X] =>> Env => X
  given Reader is Monad ...

  object Monoid:
    def unit[M](using m: M is Monoid): M

Expectation

I would expect the code to show (and be copied) just as it was written in the markdown. Either keep the indentation for all lines or remove the indentation from all lines by the same amount.