fix: Hot reload skips a lambda or async body that reaches an internal member of an unpassed file through an interpolated string handler, index or range, await using or await foreach awaiter, or generic extension method
Merged
HA
12d ago+2216+2216+0123456789012345678901234567890123456789-161-161-012345678901234567890123456789
Summary
- Hot reload now refuses a lambda or async body that reaches an internal member declared in a file the reload was not given. This covers four paths: an interpolated string handler, an index or range (
^1,a..b), the awaiter thatawait usingandawait foreachcall, and an extension method whosethisparameter is a type parameter. The method keeps running its compiled body instead of being reportedPatchedand then throwingMethodAccessException.
Follow-up to #3565, which covers the same constructs when the internal member is in the edited file.
User Impact
Before, each of these bodies was reported Patched and then threw MethodAccessException when it ran. This happened when the internal member came from a file outside the reload:
- a handler constructor,
AppendLiteral, orAppendFormatted(including aref structhandler, an addition such as$"a" + $"{x}", and an explicit cast to the handler type); Length,Count, the int indexer, orSlicebehindx[^1],x?[^1](including a nullable struct receiver), or a range. Any other element access that fails to bind, such asx[0]orx[0, ^1], now names the internal indexer itself. This also closes the gap for a plainx[0]on an internal indexer in an unpassed file. A range over a type with only an internalthis[Range]is refused too. A range whose given endpoints are ints and whose end is given, such asx[1..2]orx[..2], does not readLength, so an internalLengthalone does not refuse it;GetAwaiter,IsCompleted, orGetResultof the value a patternDisposeAsync(await using, statement and declaration forms) orMoveNextAsyncand the enumerator'sDisposeAsync(await foreach) return, and an internal instanceDisposeAsynceven when a public extension of the same name is in scope;Deconstruct<T>(this T ...)(including the element deconstruction ofawait foreach) orGetEnumerator<T>(this T ...), unconstrained or constrained toclass,struct,unmanaged, ornew(), including an array receiver, athis T[]extension, and a receiver that is itself a type parameter constrained tonew().
Now each one is Skipped:
- A lambda gets the inside-closure reason, which names the member and suggests moving the use out of the lambda.
- An async body gets the out-of-reach reason, which ends with "Run 'uloop compile'."
The hot-reload skill reference no longer lists these as not caught.
Changes
- The unpassed implicit-call lookup names the missing call for these constructs:
- Interpolated string handlers, on a string, an addition of strings, or a cast to the handler type: the handler constructor and every append call that bound to nothing.
- Index or range access, plain or after
?.: every member of the support pattern the access calls, when it bound to nothing. - Awaiters of
await usingandawait foreach: the awaiter chain, bound speculatively in a newUnpassedAwaitCallLookup. Anawait foreachis traced even when its enumerator bound, because the bound methods do not show which awaiter call failed.
- An extension method whose
thisparameter is a type parameter now matches a receiver its constraints allow:class,struct,unmanaged, andnew()(a struct, or a non-abstract type with a public parameterless constructor), andNullable<T>does not satisfystruct. An array receiver reaches this lookup too. - In the awaiter lookup, a speculative call that binds to an extension
DisposeAsyncorMoveNextAsynccounts as no method, becauseawait usingandawait foreachcall only instance methods. - A deconstruction, a foreach deconstruction, and a positional pattern now pass along their number of parts. The instance and extension lookups accept only a
Deconstructwhose parameters are exactly that many out parameters, so the reason names the method the compiled body calls. - A constructor is shown as
new Type(...)in the unpassed reason, as in the in-file reason. - First commit: a behavior-free Extract Class. The query-expression lookup moved into
UnpassedQueryCallLookup, which keeps the lookup file under the 500 SLOC limit. Tests are unchanged in that commit. - New fixtures and
TransformWorkerImplicitCallPatternLayoutTests:- 34 lambda skip cases and 31 async skip cases. They include nullable struct receivers,
this Textensions constrained toclassand tostruct, an internal instanceDisposeAsyncbeside a public extension, andx[0],x[0, ^1]andx[1..2]over internal indexers, an array receiver, athis T[]extension, and anew()type parameter in a generic local function; - deconstructions whose receiver fails a
new(),unmanagedorstructconstraint, or beside aDeconstructwith a required non-out parameter, whose reason must name the method actually called; - a two-part deconstruction and positional pattern beside an internal three-out
Deconstruct, whose reason must name the two-out one; - lambda and async cases for
[1..2]and[..2]with an internalLength, which stay entries. The run passes only the host file, so the internal members are seen through the public surface.
- 34 lambda skip cases and 31 async skip cases. They include nullable struct receivers,
Verification
uloop run-tests --filter-type class --filter-value TransformWorkerImplicitCallPatternLayoutTests:- before the fix, 40 failed;
- before the last commit, its 6 new cases failed;
- before the await foreach fix, its 2 deconstruction cases failed;
- before the cast and arity fixes, their 5 new cases failed;
- before the nullable-struct fix, its 2 new cases failed. Each constraint case fails when its constraint check is inverted;
- before the last three fixes, their new cases failed (
DisposeAsync2, constraints 2, indexers 4); - each later fix (nullable struct constraint, Range indexer, array receiver, required parameter,
this T[],new()type parameter) also failed first; - after, 76 passed.
uloop run-tests --filter-type regexover these classes: 622 passed, 0 failed.TransformWorkerImplicitCallPatternLayoutTestsTransformWorkerImplicitCallPatternTestsHotReloadImplicitCallPatternE2ETestsTransformWorkerImplicitCallTestsTransformWorkerImplicitCallLayoutTestsHotReloadImplicitCallE2ETestsHotReloadImplicitCallLayoutE2ETestsHotReloadUnpassedInternalMemberE2ETestsHotReloadIntroducedTypeCallsAddedMemberE2ETestsHotReloadObjectCreationInitializerTestsTransformWorkerPartialTypeTestsHotReloadWorkerReasonTextTests
- Extract Class commit:
TransformWorkerImplicitCallLayoutTests,HotReloadImplicitCallLayoutE2ETests, andTransformWorkerImplicitCallTestsgave 80 passed. - Code complexity (max 15), file length (max 500),
check-skill-size, andsync-tool-docs --check: no findings.
Closes #3543