Skip to content

Do local classes have companions? Typer and TreeUnpickler disagree. #14508

Open
@smarter

Description

@smarter

The logic responsible for making .companionClass/.companionModule work after unpickling is:
https://github.com/lampepfl/dotty/blob/8f99dad4664ff28b4d77e0ab0b1e6fe7c590524a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala#L847-L856
But this does not work for local classes e.g.(val x = { class C; object C; ...}) because sym.scalacLinkedClass will look for the companion in the current scope, but when unpickling we don't enter local symbols in scopes (since the pickle refers to them by their address). To fix this we could either:

This came up in #14105 which had to special-case local classes to avoid introducing a difference in behavior between typing and unpickling.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions