diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 45029a954c90..1b3f4c3d6fb1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -593,6 +593,9 @@ class Namer { typer: Typer => def setDocstring(sym: Symbol, tree: Tree)(using Context): Unit = tree match { case t: MemberDef if t.rawComment.isDefined => ctx.docCtx.foreach(_.addDocstring(sym, t.rawComment)) + case t: ExtMethods => + for meth <- t.methods.find(_.span.point == sym.span.point) do + setDocstring(sym, meth) case _ => () } diff --git a/compiler/test/dotty/tools/repl/DocTests.scala b/compiler/test/dotty/tools/repl/DocTests.scala index 0a34c6a1c498..2fb53f53fa5d 100644 --- a/compiler/test/dotty/tools/repl/DocTests.scala +++ b/compiler/test/dotty/tools/repl/DocTests.scala @@ -31,6 +31,23 @@ class DocTests extends ReplTest { assertEquals("doc", doc("new Foo")) } + @Test def docOfExtension1 = + eval("/** doc */ extension (x: Int) def foo = 0").andThen { implicit s => + assertEquals("doc", doc("extension_foo")) + } + + @Test def docOfExtension2 = + eval("extension (x: Int) /** doc */ def foo = 0").andThen { implicit s => + assertEquals("doc", doc("extension_foo")) + } + + @Test def docOfExtension3 = + eval("/** doc0 */ extension (x: Int) { /** doc1 */ def foo = 0; /** doc2 */ def bar = 0; def baz = 0 }").andThen { implicit s => + assertEquals("doc1", doc("extension_foo")) + assertEquals("doc2", doc("extension_bar")) + assertEquals("doc0", doc("extension_baz")) + } + @Test def docOfDefInObject = eval("object O { /** doc */ def foo = 0 }").andThen { implicit s => assertEquals("doc", doc("O.foo"))