Skip to content

Commit 639ca9e

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

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class Namer { typer: Typer =>
530530
* enter them into symbol table
531531
*/
532532
def indexExpanded(origStat: Tree)(using Context): Context = {
533-
def recur(stat: Tree): Context = stat match {
533+
def recur(stat: Tree, origStat: Tree): Context = stat match {
534534
case pcl: PackageDef =>
535535
val pkg = createPackageSymbol(pcl.pid)
536536
index(pcl.stats)(using ctx.fresh.setOwner(pkg.moduleClass))
@@ -542,16 +542,23 @@ class Namer { typer: Typer =>
542542
case mdef: DefTree =>
543543
val sym = createSymbol(mdef)
544544
enterSymbol(sym)
545-
setDocstring(sym, origStat)
545+
val origDef = origStat match
546+
case origStat: ExtMethods => origStat.methods.head
547+
case _: DefTree => origStat
548+
setDocstring(sym, origDef)
546549
addEnumConstants(mdef, sym)
547550
ctx
548551
case stats: Thicket =>
549-
stats.toList.foreach(recur)
552+
val origStats = origStat match
553+
case ext: ExtMethods => ext.methods
554+
case _ => Iterator.continually(origStat)
555+
for (stat, origDef) <- stats.toList.zip(origStats) do
556+
recur(stat, origDef)
550557
ctx
551558
case _ =>
552559
ctx
553560
}
554-
recur(expanded(origStat))
561+
recur(expanded(origStat), origStat)
555562
}
556563

557564
/** Determines whether this field holds an enum constant. */

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)