fix: Hot reload patches types in a namespace with a keyword-named segment such as @event
Summary
A type declared in a namespace with a keyword-named segment (for example namespace Game.@event) failed hot reload:
Type '<Namespace>.@event.<Host>' was not found in assembly '<Assembly>'.
CecilTypeNames.ToMetadataName built the namespace part with INamespaceSymbol.ToDisplayString(), which escapes keyword identifiers. Compiled metadata names the namespace event, so the host type lookup missed.
Before / After
- Before: editing a method, a property getter, or a nested type's method of a type in
...@eventgives aFailedrow with the message above. - After: the rows are
Patchedand the edited values run; RevertAll restores the compiled values.
Changes
- The segment join that #3597 added privately to
ConstDriftCollectormoved toCecilTypeNames.ToNamespaceMetadataName; bothCecilTypeNames.ToMetadataName(metadata names,/nesting) andConstDriftCollector.ToReflectionMetadataName(reflection names,+nesting) use it. Every metadata or reflection name derived fromToMetadataName(patch entry host types, method keys, introduced-type lookups,.Replace('/', '+')reflection names) is fixed by the same change. - New end-to-end tests with a fixture in a new file.
HotReloadKeywordNamespaceE2ETests: method body, property getter, call to an added method, nested type's method, const drift warning, and compiled property kind-change warning.HotReloadKeywordNamespaceIntroducedTypeE2ETests: a type introduced into the namespace by one reload and body-edited by the next.
Namespace and type display strings checked
| Site | Form | Result |
|---|---|---|
CecilTypeNames.ToMetadataName | metadata name | fixed |
OrdinaryMethodShimTypes / PropertyGetterEmitter shim namespace | C# source (namespace declaration, global:: qualified calls) | unchanged: the escaped @event is required to parse; covered by the getter and added-method tests |
ShimMethodEmitter.IsUnityEngineMonoBehaviourDerived | comparison with "UnityEngine" | unaffected |
AccessorPlan.BuildMemberKey, AccessibilityRules twin map, BaseCallRules, ExplicitImplementationMatcher, EventAccessorRules event types | symbol-to-symbol keys in one display format | unaffected |
ImplicitCallTargets.Implements, BaseCallRules / EventAccessorRules attribute checks, UnpassedInternalAccessorLookup | comparison with System.* constants | unaffected |
UnpassedAwaitCallLookup, ImplicitCallTargets, EventAccessorShimRewrite, NestedTypeNameQualifier | C# source (FullyQualifiedFormat) | unaffected |
PlannedAddedMemberNames.CollectCompiledEnumMembers | matched against CS0117 compiler messages, which use the same escaped display | unaffected |
warning / reason texts (ConstDriftCollector, CompiledMemberKindChangeWarnings, ExtensionClassNameBind, EventAccessorRules, MethodTransformDecider, ...) | display text | unaffected |
Syntax keys
The kind-change warning keys a removed compiled property by the reflection name of its type (built from symbol names, namespace event), and the drift check strips the matching snapshot declaration by a key WorkerSyntaxIndex built from syntax, which kept @event / @class. The keys never met, so the removal also raised the file-level "Edits outside method bodies" warning. WorkerSyntaxIndex now builds the type part of every syntax key from unescaped names (namespace segment and type identifier ValueText).
Comparisons of syntax keys with keys from another source, checked:
| Site | Other side | Result |
|---|---|---|
OutsideMethodBodyDriftChecker / StripHandledMemberDeclarationsRewriter vs CompiledMemberKindChangeWarnings kind-change keys | ConstDriftCollector.ToReflectionMetadataName + compiled member name | the mismatch; fixed |
RetainedDeclarationStage retained type names, OrdinaryMethodShimTypes added type key | WorkerSyntaxIndex builders | same builder on both sides |
RetainedBodyEditHome changed method / getter keys | IntroducedTypeDeclarationMemberIndex, built with WorkerSyntaxIndex | same builder |
PartialTypeParts / PartialTypePartLoader needed and changed part names | WorkerSyntaxIndex builders | same builder |
RemovedMemberCollector, AddedFieldCatalog, AddedMethodCatalog, UnsupportedMemberSkipCollector, AddedPropertyClassifier, WorkerSyntaxMemberMaps snapshot maps | WorkerSyntaxIndex builders | same builder |
None relies on the escaped form.
Member identifiers had the same split: property keys and the field keys built from declarators kept the @ of a keyword-named member (@checked, @event) while the kind-change and added-field keys use symbol names. Removing such a property, or adding such a field, raised a spurious "Edits outside method bodies" warning. Those keys now use the identifier ValueText; method and event keys are unchanged, since no test shows them crossing to a symbol-built key.
Verification
- Without the fix: the four patch tests fail with the message above, and the introduced-type test fails with "Introduced-type artifact does not define every requested type". The const drift and kind-change tests pass on
maintoo (that path was fixed by #3597); they pin the moved helper. With the fix: 10/10 pass (two more rows for a keyword-named property removal and a keyword-named field addition, both failing before the member-key fix). The two kind-change rows (keyword-named namespace, and keyword-named type@class) assert that no drift warning appears; both fail before the syntax-key fix. - The extension-class lookup is covered by
Run_ClosureCallingExtensionInKeywordNamedNamespace_IsPatchedinHotReloadNonPublicClassExtensionCallE2ETests(#3597), which passes. - Single-class runs, all passed:
TransformWorkerBaseCallTests(26),TransformWorkerPartialTypeTests(126),TransformWorkerNonPublicClassExtensionCallTests(26),HotReloadNonPublicClassExtensionCallE2ETests(9),TransformWorkerClientTests(157),TransformWorkerIntroducedTypeTests(36),TransformWorkerIntroducedTypeAccessibilityTests(50),HotReloadPartialTypeE2ETests(7). scripts/check-file-length.shand the C# part ofscripts/check-code-complexity.sh: no findings.
Fixes #3599