fix: Hot reload no longer skips or reports drift for explicit implementations of an internal interface from a file the reload was not given
Summary
Take an explicit implementation of an internal interface whose declaration sits in a file the reload was not given. Until now, every hot reload of the implementing file reported it wrong:
- Methods: the explicit method was
SkippedwithMethodTransformExplicitInterfaceImplementation, even when it was not edited. The file also got an "edits outside method bodies" warning. - Properties: an explicit property was read as an ordinary property named
Ns.IFoo.Value. Editing it wasFailedwithCS0246/CS0538from the generated shim. - Indexers and events: an explicit indexer or event accessor stayed
Skipped, as it does for a public interface. Its row label wasget_Ns.IFoo.Item/add_Ns.IFoo.Changedinstead of the compiledNs.IFoo.get_Item/Ns.IFoo.add_Changed.
Now an unedited implementation produces no row and no warning. An edited explicit method or property is patched, as it is for a public interface. Indexer and event accessors stay Skipped under their compiled names.
Fixes #3591
Cause
The worker compiles the edited files into their own assembly and sees the rest of the edited assembly only through its compiled reference. The compilation binds a declaration's interfaces with accessibility enforced. So an internal interface of that assembly does not bind as an implemented interface, and the source member's ExplicitInterfaceImplementations is empty. The method then matched no compiled counterpart and was classified as added. A property was taken for an ordinary one.
Fix
ExplicitInterfaceMemberResolverruns once per worker group. For each explicit implementation the compilation left implementing nothing, it binds the specifier with the accessibility-ignoring model. It then picks the one interface member of the same kind, name, generic arity, parameter types with ref kinds, and return or property type, in the same compilation. Accessors are mapped to the interface accessors.- It returns no match when there are zero or several candidates. That member stays an implementation of nothing, the fail-closed behavior from before.
ExplicitImplementationMatcherbecomes one object per run, holding that map. Every question about an explicit implementation now goes through it: is it explicit, its implemented member, its compiled counterpart, its row and source names. The method, property, indexer and event paths therefore all see the same answer.- "Is explicit" also looks at the declaration, so an unresolved explicit property is no longer treated as an ordinary one.
- The matcher hangs off
WorkerSourceUnitand is passed to the symbol-only helpers that need it. Those helpers took only symbols before. A symbol alone cannot answer this, because the answer depends on binding the specifier in the run's compilation.
Why not give the worker compilation access to the internals instead: I prototyped it with the compilation-wide accessibility-ignoring binder flag. It fixed these cases but also switched off every enforced binding the guards rely on. 59 existing tests failed, including bodies that resolve to a private overload being Patched where they must be Skipped. It also relies on an internal Roslyn API.
Interface-list readers
The base list still binds with accessibility enforced. I checked every reader of Interfaces / AllInterfaces / FindImplementationForInterfaceMember in the worker:
UnpassedIndexerApplicability(argument types) andUnpassedInternalExtensionLookup(receiver supertypes): covered by the rows for an internal indexer that takes the interface and an internal extension on it. Both patch and return the edited value.ImplicitCallTargets/UnpassedImplicitCallLookup: they look only forSystem.IDisposable, so they are unaffected.RetainedTypeSignatureReferenceFinder: it reads retained types bound from their artifact assembly, not source declarations, so it is unaffected.
The #3590 specifier aligner needed no change. A hidden-interface implementation respelled with global:: is reported unchanged with no warning, and that is pinned by a test.
Tests
TransformWorkerExplicitInterfaceTests:- editing only a neighbor class leaves out every hidden-interface implementation, with no warning;
- an edited explicit method of a hidden interface, of a nested hidden interface, and on a nested implementer;
- an edited explicit property;
- indexer and event accessors stay
Skippedunder their compiled names; - bodies that rely on the class implementing the hidden interface;
- the
global::respelling. - Nested types are compared in metadata form (
Outer/Nested).
HotReloadExplicitInterfaceE2ETests:- the hidden explicit method and property apply and revert;
- the three relying bodies patch and return the edited value. These three already passed before the fix and are kept as regression guards.
- All new tests except those three fail on main.