From 6c3d7adb71bfda86264e21dc15dba6b6b771b064 Mon Sep 17 00:00:00 2001 From: Chua Chee Seng Date: Fri, 5 Dec 2025 17:29:45 +0800 Subject: [PATCH] Fix duplicate member entries in Scaladoc generation Resolves an issue where Scaladoc was generating duplicate entries for the same members when combining results from multiple parser instances. The fix implements deduplication by creating a stable composite key from the member's location, full name, and kind. When duplicates are found, the entry with documentation is preferred, falling back to the first entry if none have docs. This ensures clean, non-redundant API documentation output. Co-authored-by: Bill Venners --- scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala index 4b5d4fab2a0a..8b2169ee4b36 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/TastyParser.scala @@ -169,7 +169,12 @@ object ScaladocTastyInspector: val withNewMembers = p1.withNewMembers(p2.members) if withNewMembers.docs.isEmpty then withNewMembers.withDocs(p2.docs) else withNewMembers ) - basePck.withMembers((basePck.members ++ rest).sortBy(_.name)) + // Deduplicate members coming from different parser instances by a stable key: + // (location, member fullName, kind name). + val combined = basePck.members ++ rest + val keyed = combined.groupBy(m => (m.dri.location, m.fullName, m.kind.name)) + val uniqueMembers = keyed.values.map(g => g.find(_.docs.nonEmpty).getOrElse(g.head)).toList.sortBy(_.name) + basePck.withMembers(uniqueMembers) }.toList -> inspector.rootDoc end ScaladocTastyInspector