Repository navigation
Fix regression: special case Symbol-less overloaded TermRefs in Inliner - #26853
Merged
SolalPirelli merged 1 commit intoAug 19, 2026
Merged
Conversation
Fixes scala#26623 This issue is multifaceted and somewhat difficult to explain, so please bear with me! First, the inlining data is pickled: ``` val binder$1: (Binder.foo : Binder[Int]) = Binder.foo val name$1: String = Box.$lessinit$greater$default$2[Int] Box.apply[Int]("LocalDate", name$1, binder = binder$1) ``` Take notice of the `val binder$1: (Binder.foo : Binder[Int]) = Binder.foo`. When pickling the TypeTree[TermRef(…)], when the signature of the TermRef is `Signature.NotAMethod`, then only name is pickled, without the signature (likely as optimization). Then, when compiling the second file the inlined body is unpickled (with the symbol data/ signature expectedly missing): ``` val binder$1: Binder.foo.type = Binder.foo val name$1: String = Box.$lessinit$greater$default$2[Int] Box.apply[Int]("LocalDate", name$1, binder = binder$1) ``` The true cause of the issue happens inside Inliner’s typedSelect. There, we have a selectionType call meant to change the denotation of the typed symbols (ironically commented with `Make sure that the named type has the correct denotation`), which for our case, causes the .foo to be typed with the <overloaded Binder.foo> MultiDenotation, also affecting the ValDef type, since the incorrect denotation is now cached and used for Binder.foo.type as well. So even though we do end up correctly typing the RHS of the ValDef later, we can’t change the Binary.foo.type at that point, since the denotation for Binary.foo.type is keyed by `(prefix, name)` (because of the MultiDenotation) and any fixed denotation from the actual select tree is keyed as `(prefix, symbol)` (because we know the symbol we want). The point here is we can’t fix the issue after the selectionType poisoning, it has to be before. For that I picked typedValDef, with explicit check for this kind of case in the ValDef’s type. I think, since we know that Pickler’s optimization means that the expected signature here is „NotAMethod”, and we also cannot define TermRefs (or typeTrees, for that matter) based on `Name`s (it has to be `Symbol`s) in macros, we are pretty precise about fixing this specific issue here. I haven’t been able to reengineer any other code that would break, and I did try for a long time, so hopefully this granular change is ok. I did try other fixes: * fix in tree unpickler - at that point we didn’t have information about all of the overloaded members yet, so I didn’t manage to make this work * fix in withDenotation - we could disambiguate directly in withDenotation called by selectionType, before it gets cached, worked for this case, but I though this might be too invasive and cause issues elsewhere * Removing/ rewriting the selectionType - I also thought might be too invasive, and blew up the code
SolalPirelli
approved these changes
Aug 19, 2026
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.
Fixes #26623
This issue is multifaceted and somewhat difficult to explain, so please bear with me!
First, the inlining data is pickled:
Take notice of the
val binder$1: (Binder.foo : Binder[Int]) = Binder.foo. When pickling the TypeTree[TermRef(…)], when the signature of the TermRef isSignature.NotAMethod, then only name is pickled, without the signature (likely as optimization).Then, when compiling the second file the inlined body is unpickled (with the symbol data/ signature expectedly missing):
The true cause of the issue happens inside Inliner’s typedSelect. There, we have a selectionType call meant to change the denotation of the typed symbols (ironically commented with
Make sure that the named type has the correct denotation), which for our case, causes the .foo to be typed with the MultiDenotation, also affecting the ValDef type, since the incorrect denotation is now cached and used for Binder.foo.type as well.So even though we do end up correctly typing the RHS of the ValDef later, we can’t change the Binary.foo.type at that point, since the denotation for Binary.foo.type is keyed by
(prefix, name)(because of the MultiDenotation) and any fixed denotation from the actual select tree is keyed as(prefix, symbol)(because we know the symbol we want). The point here is we can’t fix the issue after the selectionType poisoning, it has to be before.For that I picked typedValDef, with explicit check for this kind of case in the ValDef’s type. I think, since we know that Pickler’s optimization means that the expected signature here is „NotAMethod”, and we also cannot define TermRefs (or typeTrees, for that matter) based on
Names (it has to beSymbols) in macros, we are pretty precise about fixing this specific issue here. I haven’t been able to reengineer any other code that would break, and I did try for a long time, so hopefully this granular change is ok.I did try other fixes:
Have you relied on LLM-based tools in this contribution?
Yes, and I checked the output by reading the code
How was the solution tested?
New automated tests (including the issue's reproducer, if applicable) (Also spent some time trying to come up with other distinct cases causing this issue, without success)