Commit 7987a0c
authored
Fix inline export forwarder generation regression (#23126)
To explain what was happening and what the issue was:
Minimalisation:
```scala
import scala.quoted.*
package jam {
trait JamCoreDsl {
implicit inline def defaultJamConfig: this.JamConfig =
new JamConfig(brewRecRegex = ".*")
class JamConfig(val brewRecRegex: String)
inline def brew(implicit inline config: JamConfig): Unit = ???
}
private object internal extends JamCoreDsl
export internal._
}
object test {
jam.brew
}
```
would fail retyping in the inlining phase.
During typer, because we were exporting contents of `Internal`, the
compiler created forwarders (in Namer.addForwarder) for methods chosen
in the export. The forwarders looked like this:
```scala
final implicit inline def defaultJamConfig: jam.internal.JamConfig =
jam.Internal.defaultJamConfig
final inline def brew(implicit inline config: jam.internal.JamConfig):
Unit = jam.Internal.brew(config)
```
While creating them, the compiler would also try to type them. Because
those forwarder methods were inline, the compiler would call
PrepareInlineable.makeInlineable on them. That method would transform
rhs of the forwarder method, to make sure it does not reference any
private methods/objects. Since `Internal` is private (and referenced in
both exported methods, notably in brew with rhs
jam.Internal.brew(config)), an accessor inline$Internal was created, and
the forwarder method contents remapped.
Then, during inlining in the inline phase, the ReTyper was not able to
type `jam.inline$internal.brew(config)`, with `jam.inline$internal.brew`
being typed as `Nothing => Unit` (likely having remapped the argument to
Nothing in an asSeenFrom, after deciding that the prefix is not stable).
But none of this happened when I created those forwarders and accessors
manually. After some digging it turned out that the `inline$internal`
accessor method was typed as `TypeRef(ThisType(TypeRef(NoPrefix,module
class jam)),module class internal$))`, but the manually created one was
a `TermRef(ThisType(TypeRef(NoPrefix,module class jam)), object
Internal)`. It seems like the first one has an unstable prefix, so its
denotation is not typed correctly, leading to the issue.
Fixes #22593File tree
4 files changed
+52
-1
lines changed- compiler/src/dotty/tools/dotc/transform
- tests/pos
- i22593b
4 files changed
+52
-1
lines changedLines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
144 | 149 | | |
145 | | - | |
| 150 | + | |
146 | 151 | | |
147 | 152 | | |
148 | 153 | | |
| |||
| 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 | + | |
| 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 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments