You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix changeOwnerAfter by adding transformDenotations method.
With the previous commit, we get a bad owner for the "typedArgs" var
in `dotc.typer.Applications`. What happens is the following (@DarkDimius
figured it out):
Here's the code in question:
val result = {
var typedArg = ...
(code that captures typedArg)
}
There's an interplay between 3 mini-phases, which run in interleaved succession in the same
group:
Memoize
CapturedVars
Constructors
The following events happen in the order they are written:
1. typedArg is noted to be captured, so prepareValDef in CapturedVars
installs a new denotation, valid after CapturedVars, with a Ref type.
2. Memoize in transformDefDef creates a field for `result` and changes
the owner of all definitions in the right-hand side to the field,
using `changeOwnerAfter`. This gives `typedArg` a new denotation
with the owner being the field `result$local` and a validity period
from Memoize + 1 to CapturedVars + 1 (because CapturedVars has already
installed a new denotation).
3. Constructors runs intoConstructor which changes the owner again. All code
with the field as current owner becomes owned by the constructor. But
unfortunately `typedArg` is owned by the getter `result`, because that's
the denotation installed by the preceding phase, CapturedVars. So its
owner stays the `getter` even though its definition is now part of the
constructor. Boom, -Ycheck fails.
The fix applied here adds a new method `transformAfter` which can transform
all future denotations of a symbol. `changeOwnerAfter` uses this method to become
insensitive to the order in which denotations are installed.
Morale: State is hard.
0 commit comments