Support cleanup actions in class completers#23515
Merged
odersky merged 1 commit intoscala:mainfrom Jul 14, 2025
Merged
Conversation
Needed to break the loop between completion of class and companion object. If we try to complete the class first, and completion needs the companion object (for instance for processing an import) then the companion object completion would consult the companion class info for constructor that need a constructor proxy in the object. This can lead to a cyclic reference. We now break the cycle by delaying adding constructor proxies in this case to be the last completion action of the companion class.
mbovel
approved these changes
Jul 14, 2025
Member
mbovel
left a comment
There was a problem hiding this comment.
What happens if we actually do need the constructor proxy symbol while we complete the class?
I tried:
object ProtocolTransport
class MyAnnotation(arg: () => ProtocolTransport) extends scala.annotation.StaticAnnotation
import ProtocolTransport.*
@MyAnnotation(apply)
class ProtocolTransport()and was surprised to see it actually sees the symbol and then complains that the constructor proxy cannot be used as a value:
-- [E195] Type Error: defs.scala:7:14 ------------------------------------------
7 |@MyAnnotation(apply)
| ^^^^^
| constructor proxy method apply cannot be used as a value
|
| longer explanation available when compiling with `-explain`
So in that case that seems to be okay.
And in any case, we probably only enable more code to compile with this PR 👍
This was referenced Jul 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Needed to break the loop between completion of class and companion object. If we try to complete the class first, and completion needs the companion object (for instance for processing an import) then the companion object completion would consult the companion class info for constructor that need a constructor proxy in the object. This can lead to a cyclic reference.
We now break the cycle by delaying adding constructor proxies in this case to be the last completion action of the companion class.