Skip to content

Also call avoidingType when using the custom unpackProxiesFromResultType during inlining - #26893

Merged
jchyb merged 2 commits into
scala:mainfrom
dotty-staging:fix-26785-opaque-inline-regression
Sep 30, 2026
Merged

jchyb merged 2 commits into
scala:mainfrom
dotty-staging:fix-26785-opaque-inline-regression

Conversation

@jchyb

@jchyb jchyb commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

In #23792, when in unpackProxiesFromResultType I used inlined.expansion.tpe instead of Inlined.tpe, I didn't realize that when creating the inlined Inlined node and assigning type to it, avoidingType is also called:

  def assignType(tree: untpd.Inlined, bindings: List[Tree], expansion: Tree)(using Context): Inlined =
    tree.withType(avoidingType(expansion, bindings))

Without this avoidingType here, the skolem type from the minimization does not get replaced early enough, and subsequent cavoidingType calls can't see it as by that point the skolem is replaced with a term ref, causing it to effectively leak.
So as a fix, we read the avoiding type after unpacking the inlined node with inlined.epression.tpe.

Fixes #26785

Have you relied on LLM-based tools in this contribution?

Yes, and I manually checked the logic and output.

How was the solution tested?

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

@jchyb

jchyb commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor Author

https://github.com/VirtusLab/community-build3/actions/runs/32736041819/job/97458970426: softwaremill/macwire and foldables-io/skunk-tables fail with this... needs rework, I'll try to minimize those 2 since both reference inline errors (so hopefully I'll get some more test cases out of this) edit: fixed

@jchyb
jchyb force-pushed the fix-26785-opaque-inline-regression branch from eacfd30 to 0f37313 Compare August 27, 2026 10:31
* term references to symbols in `symsToAvoid`,
* term references that have a widened type of which some part refers
* to a symbol in `symsToAvoid`,
* type references to symbols in `symsToAvoid`,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous (incorrect) fix I tried relied on bringing back this behavior documented here, which turns out to have been removed a few years ago. That however broke the macwire community build test, which I minimized and added separately as a compiler test.

To minimize the confusion for other maintainers, I remove the incorrect documentation here

@jchyb
jchyb requested a review from tanishiking September 25, 2026 11:09
@jchyb
jchyb marked this pull request as ready for review September 25, 2026 11:09

@tanishiking tanishiking left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that:
normally, the return type of an inline method has inlined.tpe which has avoidingType so that local terms/types don't leak outside.

However, for a transparent inline, the return type is refined by returning the expanded type of the inline via unpackProxiesFromResultType, and that type was not being avoided.
And, as a result, when the return value of a transparent inline was a value whose type contained a local proxy (usually because of nested inline methods), that local proxy appeared in the return type, and assertion fail.

This fix avoids the expanded type when computing the return type of a transparent inline. I think this is a reasonable fix 👍

@jchyb

jchyb commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you so much! I just noticed I left the old title for the PR, will change before merging. Sorry about that :( I probably made things unnecessarily confusing because of that.

@jchyb jchyb changed the title Experiment: Make TypeOps avoid symbols if they widen to another avoided symbol Also call avoidingType when using the custom unpackProxiesFromResultType Sep 30, 2026
@jchyb jchyb changed the title Also call avoidingType when using the custom unpackProxiesFromResultType Also call avoidingType when using the custom unpackProxiesFromResultType during inlining Sep 30, 2026
@jchyb jchyb added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Sep 30, 2026
@jchyb
jchyb merged commit c202f34 into scala:main Sep 30, 2026
64 checks passed
@jchyb
jchyb deleted the fix-26785-opaque-inline-regression branch September 30, 2026 07:21
@WojciechMazur WojciechMazur added this to the 3.10.1 milestone Oct 11, 2026
@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 Oct 11, 2026
WojciechMazur added a commit that referenced this pull request Oct 11, 2026
…romResultType during inlining" to 3.10.1 (#27283)

Backports #26893 to the 3.10.1-RC1.

PR submitted by the release tooling.
[skip ci]
@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 Oct 11, 2026
tgodzik pushed a commit to scala/scala3-lts that referenced this pull request Nov 17, 2026
…ype during inlining (scala#26893)

In scala#23792, when in
`unpackProxiesFromResultType` I used inlined.expansion.tpe instead of
Inlined.tpe, I didn't realize that when creating the inlined Inlined
node and assigning type to it, avoidingType is also called:

```scala
  def assignType(tree: untpd.Inlined, bindings: List[Tree], expansion: Tree)(using Context): Inlined =
    tree.withType(avoidingType(expansion, bindings))
```
Without this avoidingType here, the skolem type from the minimization
does not get replaced early enough, and subsequent cavoidingType calls
can't see it as by that point the skolem is replaced with a term ref,
causing it to effectively leak.
So as a fix, we read the avoiding type after unpacking the inlined node
with inlined.epression.tpe.

Fixes scala#26785 

## Have you relied on LLM-based tools in this contribution?

<!-- Pick one; "running tests" is not enough; refer to
https://github.com/scala/scala3/blob/main/LLM_POLICY.md for details -->

Yes, and I manually checked the logic and output.

## How was the solution tested?

<!-- Pick one; exceptions must have a very good reason -->

New automated tests (including the issue's reproducer, if applicable)
[Cherry-picked c202f34]
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.

Singleton type leaks from transparent inline method with double opaque types

3 participants