feat: Hot reload applies lambda and async calls to extension methods of an internal static class
Summary
Closes #3544.
A lambda, local function or async body that called an extension method of an internal static class was skipped: the worker refused the accessor because its bind names a non-public class. Such calls are now hot reloaded when the class is declared in a file the reload passes or pulls back in.
Out of scope: a class declared in a file the reload does not see. The worker sees that class only through the compiled assembly's public surface:
- an
internalmethod of it is not recognized as inaccessible, which is #3596 (currently Patched, then it throws); - a
publicmethod of it stays Skipped, because the accessibility-enforcing binding cannot prove which overload the source calls.
Changes
-
Bind the class by name. The accessor of an extension method now binds with
global::System.Type.GetType("<Namespace>.<Class>, <TargetAssembly>", true)instead oftypeofwhen the class is not externally visible, in the edited source or in the compiled assembly. An extension method's class is always top-level, non-generic and static, so its metadata name alone finds it. Other non-public classes stay refused.- Measured in review:
typeofof such a class also binds under the Editor's Mono. A mutation that always emitstypeofkept every E2E green. - The name lookup does not rely on that. Whether to keep it is #3598.
- Measured in review:
-
Bind the method the edited source calls. A public method of an internal class declared in the edited file exists in both the edited source and the compiled metadata, so the worker's binding is ambiguous. The accessor now takes the compiled candidate whose class, name, arity and parameter types match the overload the accessibility-enforcing binding resolves. Before, the twin chosen for refusal could be any overload:
Step(int, string)failed the whole file with CS1503, andPick(long)was silently called instead ofPick(int). -
Fail closed when the overload is unproven. These calls are refused with the class-not-visible reason, the same reason as before:
- a call whose overload the enforcing binding cannot resolve (it cannot resolve a class declared only in a file the reload does not see);
- a call whose return type changed in the same edit.
-
Read
[Conditional]from the edited overload. A compiled twin still carries the attributes of the last compile. Without this, an edit that made the method conditional was bound and called, although the compiler omits the call. -
Static-form calls. In
Extensions.Method(receiver, ...)the class name no longer refuses the body when the call itself is rewritten, because the rewritten call no longer names the class. This covers:- a call rewritten to an accessor;
- a call to a method this reload adds to another class;
- a call from a lambda inside the internal class to a method this reload adds to that class.
A class name anywhere else in the body is still refused.
-
Metadata names of keyword-named namespaces.
ConstDriftCollector.ToReflectionMetadataNamenow builds the namespace part from the namespace symbols' names.ToDisplayStringescaped a segment such as@event, so lookups missed the type. The host-type name inCecilTypeNames.ToMetadataNamehas the same flaw and still fails a file whose host is in such a namespace; that is out of scope and tracked as #3599. -
Look a class up only in its own assembly. The compiled class is looked up only for a class of the patch target, so a same-named class of another assembly is never bound.
-
Plumbing. The target assembly symbol and name now flow from the transform decider into
AccessorEligibilityand the shim type builders.
Behavior changes pinned by existing tests
The ExtensionCall_* tests in TransformWorkerAddedMemberAccessTests and HotReloadExtensionCallE2ETests fixed the old behavior (Skipped). They now assert the new contract:
- the worker tests assert the by-name bind and the parameter types of the bound overload;
- the E2E tests apply the edit in the running Editor and check the returned value, including the better-overload case, a class made public in the same edit, and a method added in the same reload.
Tests
TransformWorkerNonPublicClassExtensionCallTestsandHotReloadNonPublicClassExtensionCallE2ETests(new) cover:- the shapes that become entries: reduced, static, chained and async calls, and a public method of an internal class;
- the shapes that stay refused, each with its reason;
- a class added in this reload, and a class declared in a file the reload does not pass.
- Twin and non-twin return-type changes stay Skipped and never fail the file.
- Mutations, all killed:
- returning the arbitrary twin;
- dropping the registrar's overload proof;
- dropping its return-type comparison;
- the earlier gate, compiled-class, receiver, defer and registered-call checks.
- New pinned cases:
- a static-form call to an added extension binds no accessor;
- when the added method itself is skipped, its caller is skipped too;
- a class made public in the same edit, with an internal method;
- a method made
[Conditional]in the same edit; - a lambda in the internal class calling its own added method;
- an extension class in a keyword-named namespace (worker test and E2E).
- More mutations, all killed:
- ignoring the compiled class's visibility (killed by the bind-string worker test only, since
typeofalso binds); - dropping the edited-overload
[Conditional]check; - not counting added-method rewrites;
- escaping the namespace again.
- ignoring the compiled class's visibility (killed by the bind-string worker test only, since
- The
UnityCLILoop.Tests.Editor.HotReloadassembly, run in two regex batches after the last change, with no failures:\.HotReload\.TransformWorker: 1456 passed;\.HotReload\.(?!TransformWorker): 4581 passed, 4 skipped (ignored tests).
Docs
uloop-hot-reload references/scope-and-limits.md: the accessor row now states when an extension method of an internal class applies and when it is refused. The type-reference row names the static-form exception. Skill copies are regenerated.