Skip to content

Fixes #25801: Handle TypeDefs in ensureHasSym - #26011

Merged
odersky merged 1 commit into
scala:mainfrom
soronpo:claude/fix-scala-25801-WqL6Q
May 14, 2026
Merged

odersky merged 1 commit into
scala:mainfrom
soronpo:claude/fix-scala-25801-WqL6Q

Conversation

@soronpo

@soronpo soronpo commented May 8, 2026

Copy link
Copy Markdown
Contributor

When a class has a self-type that refines a member, the symbol of a TypeDef in its body can resolve through the self-type prefix to a different symbol than the one being defined. This caused two problems:

  • During TASTy unpickling, tree.ensureHasSym(sym) for a TypeDef tried to call sym.asTerm.name, which crashes with "asTerm called on not-a-Term" when sym is a type symbol.
  • During typer, the TypeDef tree's symbol was never reconciled with the intended sym, so -Ycheck:all would report the trait body as missing the type member.

Use sym.name in ensureHasSym so the produced NamedType correctly selects between TypeRef and TermRef based on the name kind, and call ensureHasSym from typedTypeDef so the typed tree carries the right symbol before pickling.

Fixes #25801

How much have you relied on LLM-based tools in this contribution?

Extensively, but it's a small fix.

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

When a class has a self-type that refines a member, the symbol of a TypeDef
in its body can resolve through the self-type prefix to a different symbol
than the one being defined. This caused two problems:

- During TASTy unpickling, `tree.ensureHasSym(sym)` for a TypeDef tried to
  call `sym.asTerm.name`, which crashes with "asTerm called on not-a-Term"
  when sym is a type symbol.
- During typer, the TypeDef tree's symbol was never reconciled with the
  intended sym, so `-Ycheck:all` would report the trait body as missing
  the type member.

Use `sym.name` in `ensureHasSym` so the produced `NamedType` correctly
selects between `TypeRef` and `TermRef` based on the name kind, and call
`ensureHasSym` from `typedTypeDef` so the typed tree carries the right
symbol before pickling.

https://claude.ai/code/session_01Gu4rX4Ywk7zkf8yPqvvwNG
@soronpo
soronpo marked this pull request as ready for review May 8, 2026 18:38
@odersky
odersky merged commit 91c4a55 into scala:main May 14, 2026
45 checks passed
@WojciechMazur WojciechMazur added this to the 3.9.0 milestone May 26, 2026
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.

AssertionError asTerm called on not-a-Term type Api when unpickling type Api from TASTy

4 participants