Commit 819d127
Inlines: decide sealing against original target, while using widened type as cast destination (scala#25448)
Fixes scala#25417 fixes
scala#25427
Regression introduced by
tanishiking@816fc6c
(scala#25111), which fixed
scala#25091.
Background:
- scala#25091 showed that inline
sealing could cast target contains method-reference that results in
`notype` at erasure.
- scala#25111 fixed this by using
`target.widenIfUnstable` to remove method-reference from cast
destination, and use it's return type instead.
- However, deciding adaptation against the widened type is too weak and
could skip a required cast, and leak projected opaque-proxy types
(scala#25417).
For example:
```scala
import scala.compiletime.summonInline
trait MyEvidence[T]
object Scope:
opaque type T = String
inline given MyEvidence[T] with {}
inline def summonInlineNoOpProxy: MyEvidence[Scope.T] =
summonInline[MyEvidence[Scope.T]]
val smoke = (
summonInline[MyEvidence[Scope.T]],
summonInlineNoOpProxy,
)
```
For `summonInline[MyEvidence[Scope.T]]`:
- `inlined.tpe`:
`Scope.type{type T = String}#given_MyEvidence_T`
- `target` (before widening):
`(Scope.given_MyEvidence_T : => Scope.given_MyEvidence_T)`
- `resultType = target.widenIfUnstable`:
`Scope.given_MyEvidence_T`
Previously
- `inlined.tpe <:< resultType` hold, so adaptation is skipped.
- Therefore, no cast is inserted, inlined tree type
remains`Scope.type{type T = String}#given_MyEvidence_T`
- This is seen as `MyEvidence[String]`
- Later typing fails for required `MyEvidence[Scope.T]` vs
`MyEvidence[String]` (path dependence infor is dropped).
---
This commit fixes the problem by: decide whether adaptation is needed
against original `target` (the real call-site contract), while using
`target.widenIfUnstable` as a cast destination, so that
scala#25091 fix)
`target.widenIfUnstable` is an upper approximation of `target`.
Conformance to widened type is weaker than conformance to original
`target`.
Therefore adaptation-need must be checked against `target`, while
widened type is used only as cast destination.
<!-- Fixes #XYZ (where XYZ is the issue number from the issue tracker)
-->
<!-- TODO description of the change -->
<!-- Ideally should have a title like "Fix #XYZ: Short fix description"
-->
<!--
TODO first sign the CLA
https://contribute.akka.io/cla/scala
-->
<!-- if the PR is still a WIP, create it as a draft PR (or convert it
into one) -->
## How much have your relied on LLM-based tools in this contribution?
<!--
State clearly in the pull request description,
whether LLM-based tools were used and to what extent
(extensively/moderately/minimally/not at all)
-->
<!--
Refer to our [LLM usage
policy](https://github.com/scala/scala3/blob/main/LLM_POLICY.md) for
rules and guidelines
regarding usage of LLM-based tools in contributions.
-->
Worked with GPT5.3-Codex
## How was the solution tested?
`testCompilation (i25091|i25417|i25427)`
<!--
If automated tests are included, mention it.
If they are not, explain why and how the solution was tested.
-->
## Additional notes
<!-- Placeholder for any extra context regarding this contribution. -->
<!--
When in doubt, and for support regarding contributions to a particular
component of the compiler,
refer to [our contribution
guide](https://github.com/scala/scala3/blob/main/CONTRIBUTING.md),
and feel free to tag the maintainers listed there for the area(s) you
are modifying.
-->
Co-authored-by: Matt Bovel <matthieu@bovel.net>1 parent 5b0f56d commit 819d127
File tree
3 files changed
+53
-2
lines changed- compiler/src/dotty/tools/dotc/inlines
- tests/pos
3 files changed
+53
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| 626 | + | |
| 627 | + | |
626 | 628 | | |
627 | 629 | | |
628 | 630 | | |
629 | 631 | | |
630 | 632 | | |
631 | | - | |
632 | | - | |
| 633 | + | |
633 | 634 | | |
634 | 635 | | |
635 | 636 | | |
636 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
637 | 649 | | |
638 | 650 | | |
639 | 651 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments