fix: Hot reload skips a lambda or async body whose interpolated string handler calls an internal member when the project declares the handler attribute in a file the reload was not given
Merged
HA
13d ago+578+578+012345678901234567890123456789-6-6-0123456789
Summary
- Hot reload now refuses a lambda or async body whose interpolated string handler calls an internal member, also when the project declares
InterpolatedStringHandlerAttributeitself in a file the reload was not given. The method keeps running its compiled body instead of being reportedPatchedand then throwingMethodAccessException.
User Impact
- On a Unity version whose base class library lacks
InterpolatedStringHandlerAttribute, a project declares its own copy, usuallyinternaland in a file of its own. - Before, editing a file that declares a handler type with an internal
AppendFormatted(or another internal handler member) reported a lambda or async body that uses it asPatched. The body then threwMethodAccessExceptionwhen it ran. This happened when the attribute's file was not part of the reload. - Now that body is
Skippedwith the implicit-call reason, which names the internal member and "an interpolated string handler".
Cause
- The worker reads the target assembly through its public surface, so the internal attribute in an unpassed file did not bind.
- Without the attribute, the handler type looked like an ordinary type. Its interpolated strings made no handler calls, so the existing check never ran.
- The shim compile reads the attribute from metadata, so it built the handler and called the internal member.
- The
+operand and the captured local in the original report were not the cause. When the attribute file is passed, those shapes are alreadySkipped.
Changes
- When the target assembly declares the attribute and the worker compilation has no accessible declaration of it, the worker compilation gets a binding-only
internaldeclaration. Handler types are then recognized, and the existing handler check runs. - The guard checks accessibility on purpose.
GetTypeByMetadataNamealso returns an internal copy from another assembly, which cannot bind, so the target's own internal copy alone must not count. - The compilation is left unchanged when a passed file or a public reference already declares the attribute, so the name never becomes ambiguous.
- The target assembly with every member visible is resolved once. It is resolved again only when the declaration is added.
- New tests for the user layout. A new fixture assembly,
UnityCLILoop.Tests.Editor.HotReloadHandlerAttributeFixture, references no other assembly that declares the attribute. The attribute is internal in one file, and the handler and bodies are in another, which alone is passed.TransformWorkerHandlerAttributeTests: a plain call and the reported shape (a+operand with a captured local), each as a lambda and an async body. All four must beSkippedwith the full implicit-call reason namingAppendFormatted.HotReloadHandlerAttributeE2ETests: the lambda through the orchestrator must beSkipped, with no failed row, and keep the compiled value.
- Tests in the main test assembly:
TransformWorkerImplicitCallPatternLayoutTests: a plain call and the reported shape (a+operand with a captured local), each as a lambda and an async body.HotReloadImplicitCallPatternE2ETests: one E2E case.- That assembly references a DLL that carries its own internal copy of the attribute. Two inaccessible copies make the metadata lookup ambiguous, so these cases reached the new path even with the first, accessibility-blind guard. They are kept as coverage for that layout.
Verification
- Red first:
- The new fixture assembly's four worker cases and its E2E case failed with the accessibility-blind guard of 706b48df5. Every body stayed an entry, and the E2E row was
Patched. - Before any fix, the four main-assembly worker cases stayed entries and its E2E row was
Patched. - Making the attribute declaration
publicalone turned the plain-call pairSkipped, which confirmed the cause.
- The new fixture assembly's four worker cases and its E2E case failed with the accessibility-blind guard of 706b48df5. Every body stayed an entry, and the E2E row was
- After the fix:
TransformWorkerHandlerAttributeTests,HotReloadHandlerAttributeE2ETests,TransformWorkerImplicitCallPatternLayoutTestsandHotReloadImplicitCallPatternE2ETests: 90 passed, 0 failed. After the last two fixture cases were added, the two new classes ran again: 5 passed, 0 failed.uloop run-tests --filter-type regex '\.TransformWorker[A-Za-z]*Tests\.': 1260 passed, 0 failed. Every worker run against the main test assembly takes the new path.- E2E regression (implicit call, pattern, layout, unpassed internal member, introduced type, object creation, public class extension, reason text), on the first fix: 310 passed, 0 failed.
- Code complexity (max 15) and file length (max 500): no findings.
Closes #3573