Skip to content

Fix Scala 2 nested-object display and several signature bugs#87

Open
rochala wants to merge 2 commits into
mainfrom
worktree-fix-scala-2-nested-objects
Open

Fix Scala 2 nested-object display and several signature bugs#87
rochala wants to merge 2 commits into
mainfrom
worktree-fix-scala-2-nested-objects

Conversation

@rochala

@rochala rochala commented May 26, 2026

Copy link
Copy Markdown
Contributor

Problem

Querying a Scala 2 sealed ADT — the idiomatic sealed trait T; object T { case object A extends T } pattern — produced garbled output:

  • Subtype names used JVM $-encoding (CellarADT$.CellarAA$ instead of CellarADT.CellarAA)
  • The module class appeared as a spurious third result block alongside the trait and the object
  • Zero-param defs were missing the ': ReturnType' colon (def isValid instead of def isValid: Boolean)
  • Generic methods with a plain return type were missing the colon too ([A]List[A] instead of [A]: List[A])
  • <init> constructor symbols leaked into member listings
  • Scala 2 package-object prefix appeared in type names (package.List instead of List)

Changes

GetFormatter

  • normalizeScala2FQN: strips $.. and trailing $ from displayFullName; applied to heading, Origin field, and subtype list so all user-visible names use source-level dotted notation
  • renderMembers: handle TermSymbol (module val) by delegating to its module class, so standalone objects keep their members after the module-class deduplication

PublicApiFilter

  • Filter <init> constructor symbols from member listings

SymbolResolver

  • Deduplicate module classes whose module val is also in the result set; findStaticModuleClass returning raw Foo$ alongside findStaticTerm returning the object val previously produced a spurious third block

TypePrinter

  • TermSymbol with a plain Type declared type (Scala 2 zero-param def): render as def foo: T instead of def fooT
  • PolyType result: add ': ' separator before the return type when the result is a plain Type
  • TypeRef prefix: skip prefix when it prints as "package" to suppress the Scala 2 package-object artefact

New fixture: fixtureScala2/src/cellar/fixture/scala2/CellarADT.scala — sealed ADT with companion-nested subtypes

🤖 Generated with Claude Code

rochala and others added 2 commits May 26, 2026 23:58
Adds cellar.fixture.scala2.CellarADT — a sealed trait whose subtypes
(CellarAA, CellarAB) live inside its companion object, which is the
idiomatic Scala 2 ADT pattern.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Problem
-------
Querying a Scala 2 sealed ADT (sealed trait T; object T { case object A
extends T }) produced garbled output: subtype names used JVM $-encoding
(CellarADT$.CellarAA$), module class appeared as a third duplicate
result block, zero-param defs were missing the ': ReturnType' colon,
<init> constructors leaked into member lists, and the package-object
prefix ('package.List') was not stripped from Scala 2 type names.

Changes
-------
GetFormatter
- normalizeScala2FQN: strips '$.' → '.' and trailing '$' from
  displayFullName; applied to heading FQN, Origin field, and subtype
  list so all user-visible names use source-level dotted notation.
- renderMembers: handle TermSymbol (module val) by delegating to its
  module class, so standalone objects keep their members after the
  module-class deduplication in SymbolResolver.

PublicApiFilter
- Filter <init> constructor symbols from member listings.

SymbolResolver
- Deduplicate module classes whose module val is also in the result
  set; findStaticModuleClass returning raw Foo$ alongside findStaticTerm
  returning the object val previously produced a spurious third block.

TypePrinter
- TermSymbol with a plain Type declared type (Scala 2 zero-param def):
  render as 'def foo: T' instead of 'def fooT' (was missing the colon).
- PolyType result type: add ': ' separator before the return type when
  the result is a plain Type (e.g. '[A]: List[A]' not '[A]List[A]').
- TypeRef prefix: skip prefix when it prints as 'package' to suppress
  the Scala 2 package-object artefact ('package.List' → 'List').

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant