fix: Hot reload no longer reports drift or removed members when an edit only respells an explicit interface specifier
Summary
If an edit only respells an explicit interface specifier (void IFoo.Run() becomes void global::Ns.IFoo.Run()), hot reload applied the edit but also reported warnings for the file:
- an "edits outside method bodies" warning;
- a removed member;
- for an explicit property or event, a "compiled property/event was removed" warning.
None of these warnings is reported now. The edit itself is applied as before.
Why not keys built from the implemented member
The issue proposed building syntax keys from the implemented interface member. Re-keying alone is not enough. Once the keys pair, the drift check compares the two declarations with SyntaxFactory.AreEquivalent, and the residual tree compare compares the whole file. Both still see the old spelling, so they would still report the member.
Instead, the snapshot tree is aligned once, before any map is built. Each snapshot specifier that the current source spells another way is replaced by the current spelling. The 26 key builders are unchanged.
A specifier is replaced only when all of these hold:
- the current source holds an implementation of the same member (type, kind, name, arity and parameters) with a different spelling;
- the snapshot declaration, bound in the snapshot source, and the current declaration, bound in the current source, name the same interface and the same parameter types;
- exactly one current implementation matches.
In every other case the snapshot is kept, and the member is reported as before.
The snapshot is bound in its own source: a copy of the compilation with the snapshot tree in place of the current one. A using directive the edit changed can make the old text name another interface, or another parameter type, at the current position. The copy is built only when some specifier is spelled differently.
The parameter types are compared as well as the interface. A retargeted using alias can move IFoo.Take(Arg) from Take(A) to Take(B) of the same interface, while the text stays the same.
Types are compared by their fully qualified display, as ExplicitImplementationMatcher already does, because symbols from two compilations are never equal. A type with an unbound part never matches.
Both bindings enforce accessibility, for two reasons:
- It resolves twin-typed arguments such as
Memory<int>. - It agrees with the rest of the reload. The compilation binds a declaration's interfaces with accessibility enforced, so an explicit implementation of an internal interface declared in a file the reload was not given implements nothing anywhere in the reload. Every edit of such a file already skips that member and reports drift, on main too. That case is #3591; the aligner does not pair it.
Kind-change warning
CompiledMemberKindChangeWarnings looked up a compiled explicit property or event by its compiled name (Ns.IFoo.Changed). The compiler copies the specifier spelling into the source symbol's name (global::Ns.IFoo.Changed), so a respelled property or event was reported as removed. The check now also accepts a source member that explicitly implements the same interface property or event.
Behaviour change
An explicit implementation whose edit only respells the specifier is now reported unchanged under its compiled name, with no entry, like any other unedited method. For a respelled explicit property whose getter is edited, the unedited setter no longer gets an entry.
Tests
TransformWorkerExplicitInterfaceTests. Red first: 7 tests failed before the fix.
- The
global::respelled method, with an edited body, no longer gets either warning. A method that is only respelled is reported unchanged with no entry. - The respelled property no longer gets a warning, and its setter no longer gets an entry. The test that pinned the old behaviour now asserts this.
- An indexer and an event that are only respelled get no warning. A new explicit event fixture was added for the event.
- With a using alias, nothing is reported as removed and there is no member-named drift label. The added using line is itself an edit outside method bodies, so the file may still be reported for it.
- Negative cases, each still reported as a removed member:
- an implementation moved to another interface that declares the same member;
- an implementation moved to another interface by a retargeted using alias, then respelled;
- an implementation moved to another overload by a retargeted using alias, then respelled.
- Negative: an explicit property moved to another interface with a property of the same name is still reported as a removed compiled property.
Mutations, each reverted after the run:
- Aligning by shape alone fails the three removed-member negatives.
- Dropping the parameter types from the comparison fails the overload negative.
- Binding the snapshot under the current using directives fails both alias negatives.
- Matching the kind-change check by name alone fails the moved-property negative.
- Dropping the property kind-change fix fails the property test.
- Dropping the event kind-change fix fails the event test.
Regression runs:
TransformWorker*and reason-text tests: 1576 passed.- Explicit-interface E2E, sibling baseline, pause-point, added-member, retained-artifact and introduced-type classes: 587 passed, 1 skipped (an existing ignore).
Closes #3549