fix: Hot reload skips a lambda or async body whose interpolated string handler, index or range, or await using and await foreach awaiter calls an internal member instead of failing at run time
Summary
- Hot reload now refuses a lambda or async body that reaches an internal member through an interpolated string handler, an index or range (
^1,a..b), or the awaiter thatawait usingandawait foreachcall. The method keeps running its compiled body instead of being reportedPatchedand then throwingMethodAccessException.
User Impact
Before, each of these bodies was reported Patched. When it ran, it threw MethodAccessException from the shim's closure or state machine. Each case below was reproduced from both a lambda and an async body:
- an interpolated string handler whose constructor,
AppendLiteral, orAppendFormattedis internal. This includesref structhandlers, a string converted to a handler-typed local, and an addition such as$"a" + $"{x}"; x[^1],x?[^1], orx[1..^1]on a type whoseLengthorCountis internal, andx[^1]orx[1..^1]whose int indexer getter orSliceis internal;await usingon a resource whose public patternDisposeAsyncreturns an awaitable with an internalGetAwaiter,IsCompleted, orGetResult. This covers both the statement form and the declaration form;await foreachwhoseMoveNextAsync, or whose enumerator'sDisposeAsync, returns such an awaitable.
Now each of these is Skipped with the implicit-call reason. A range whose given endpoints are ints and whose end is given, such as x[1..2] or x[..2], never reads Length, so an internal Length alone does not refuse it. For example: "inaccessible method 'Length' that the compiler calls for an index or range has no accessor rewrite shape." The compiled body keeps working, and no row fails.
Out of scope:
fixedwith an internalGetPinnableReferencealready fails loudly, because shims compile without unsafe code. Unsafe bodies are tracked separately.- A query clause that follows a clause that binds to nothing is already
Skipped. - An internal indexer or
Slicein the edited file was already refused by the accessor check.
Next: a follow-up PR covers the same constructs when the internal member lives in a file the reload was not given, plus an internal extension method whose this parameter is a type parameter. Until then, the hot-reload skill reference tells users to run uloop compile for that edit.
Changes
- The transform worker's implicit-call check gained three cases:
- Interpolated string handlers: it reads the handler creation operation on the string or on the addition of strings it belongs to, whatever the parent is, and checks the constructor and every append call.
- The implicit Index and Range support, plain or after
?.: it checksLength/Countwhen the access reads it, and the indexer (getter, or setter for an assignment target) orSlice. - The awaiter of the value
DisposeAsync/MoveNextAsync/ the enumerator'sDisposeAsyncreturns: the Roslyn version the worker uses has no public API for that awaiter, soawait default(R)is bound speculatively at the statement.
- New construct names in the reason: "an interpolated string handler", "an index or range", "await foreach". A constructor is shown as
new Type(...). - The hot-reload skill reference lists the new constructs and names the unpassed-file cases that are not caught yet.
- New fixtures and tests. Each case has a lambda variant and an async variant, plus an all-public control per construct and one end-to-end test per construct family. Two more end-to-end tests patch a lambda that slices
[1..2]or[..2]on a type with an internalLength, then run it. The fixtures declareInterpolatedStringHandlerAttributeasinternal, because Unity's 4.8 reference profile lacks it. With the attribute internal, every case binds identically under both the accessibility-ignoring and the strict semantic model.
Verification
uloop run-tests --filter-type regexoverTransformWorkerImplicitCallPatternTests,HotReloadImplicitCallPatternE2ETests,TransformWorkerImplicitCallTests,TransformWorkerImplicitCallLayoutTests,HotReloadWorkerReasonTextTests,HotReloadImplicitCallE2ETests,HotReloadImplicitCallLayoutE2ETests: 297 passed, 0 failed.- Before the fix, the new worker tests failed: 34 failed, and the 4 controls passed. The review follow-ups were also red first: 9 tests failed before them, then all tests in the two pattern classes passed (60 after the open-start follow-up).
dotnet run --project tools/UnityCliLoop.CodeComplexity -- --root . --max-complexity 15: no findings.check-skill-sizeandsync-tool-docs --check: pass.
Refs #3543