Skip to content

Commit 856adb3

Browse files
committed
Fix #9339: Register doc of extension methods
1 parent 5cdfd31 commit 856adb3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ class Namer { typer: Typer =>
593593
def setDocstring(sym: Symbol, tree: Tree)(using Context): Unit = tree match {
594594
case t: MemberDef if t.rawComment.isDefined =>
595595
ctx.docCtx.foreach(_.addDocstring(sym, t.rawComment))
596+
case t: ExtMethods =>
597+
for meth <- t.methods.find(_.span.point == sym.span.point) do
598+
setDocstring(sym, meth)
596599
case _ => ()
597600
}
598601

compiler/test/dotty/tools/repl/DocTests.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ class DocTests extends ReplTest {
3131
assertEquals("doc", doc("new Foo"))
3232
}
3333

34+
@Test def docOfExtension1 =
35+
eval("/** doc */ extension (x: Int) def foo = 0").andThen { implicit s =>
36+
assertEquals("doc", doc("extension_foo"))
37+
}
38+
39+
@Test def docOfExtension2 =
40+
eval("extension (x: Int) /** doc */ def foo = 0").andThen { implicit s =>
41+
assertEquals("doc", doc("extension_foo"))
42+
}
43+
44+
@Test def docOfExtension3 =
45+
eval("/** doc0 */ extension (x: Int) { /** doc1 */ def foo = 0; /** doc2 */ def bar = 0; def baz = 0 }").andThen { implicit s =>
46+
assertEquals("doc1", doc("extension_foo"))
47+
assertEquals("doc2", doc("extension_bar"))
48+
assertEquals("doc0", doc("extension_baz"))
49+
}
50+
3451
@Test def docOfDefInObject =
3552
eval("object O { /** doc */ def foo = 0 }").andThen { implicit s =>
3653
assertEquals("doc", doc("O.foo"))

0 commit comments

Comments
 (0)