Skip to content

Fix regression: special case Symbol-less overloaded TermRefs in Inliner - #26853

Merged
SolalPirelli merged 1 commit into
scala:mainfrom
dotty-staging:fix-i26623-valdef-termref-inlining
Aug 19, 2026
Merged

SolalPirelli merged 1 commit into
scala:mainfrom
dotty-staging:fix-i26623-valdef-termref-inlining

Conversation

@jchyb

@jchyb jchyb commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #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 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 be Symbols) 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

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)

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 SolalPirelli added this to the 3.9.0 milestone Aug 19, 2026
@SolalPirelli SolalPirelli added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Aug 19, 2026
@SolalPirelli
SolalPirelli merged commit 2ae5341 into scala:main Aug 19, 2026
62 of 63 checks passed
@SolalPirelli
SolalPirelli deleted the fix-i26623-valdef-termref-inlining branch August 19, 2026 08:14
@WojciechMazur WojciechMazur added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Aug 19, 2026
WojciechMazur added a commit that referenced this pull request Aug 19, 2026
…s in Inliner" to 3.9.0 (#26860)

Backports #26853 to the 3.9.0-RC6.

PR submitted by the release tooling.
@WojciechMazur WojciechMazur added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:done This PR was successfully backported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typer regression for macros using class with default parameters list under separate compilation units

3 participants