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-161

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 that await using and await foreach call, and an extension method whose this parameter is a type parameter. The method keeps running its compiled body instead of being reported Patched and then throwing MethodAccessException.

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, or AppendFormatted (including a ref struct handler, an addition such as $"a" + $"{x}", and an explicit cast to the handler type);
  • Length, Count, the int indexer, or Slice behind x[^1], x?[^1] (including a nullable struct receiver), or a range. Any other element access that fails to bind, such as x[0] or x[0, ^1], now names the internal indexer itself. This also closes the gap for a plain x[0] on an internal indexer in an unpassed file. A range over a type with only an internal this[Range] is refused too. A range whose given endpoints are ints and whose end is given, such as x[1..2] or x[..2], does not read Length, so an internal Length alone does not refuse it;
  • GetAwaiter, IsCompleted, or GetResult of the value a pattern DisposeAsync (await using, statement and declaration forms) or MoveNextAsync and the enumerator's DisposeAsync (await foreach) return, and an internal instance DisposeAsync even when a public extension of the same name is in scope;
  • Deconstruct<T>(this T ...) (including the element deconstruction of await foreach) or GetEnumerator<T>(this T ...), unconstrained or constrained to class, struct, unmanaged, or new(), including an array receiver, a this T[] extension, and a receiver that is itself a type parameter constrained to new().

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 using and await foreach: the awaiter chain, bound speculatively in a new UnpassedAwaitCallLookup. An await foreach is traced even when its enumerator bound, because the bound methods do not show which awaiter call failed.
  • An extension method whose this parameter is a type parameter now matches a receiver its constraints allow: class, struct, unmanaged, and new() (a struct, or a non-abstract type with a public parameterless constructor), and Nullable<T> does not satisfy struct. An array receiver reaches this lookup too.
  • In the awaiter lookup, a speculative call that binds to an extension DisposeAsync or MoveNextAsync counts as no method, because await using and await foreach call 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 Deconstruct whose 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 T extensions constrained to class and to struct, an internal instance DisposeAsync beside a public extension, and x[0], x[0, ^1] and x[1..2] over internal indexers, an array receiver, a this T[] extension, and a new() type parameter in a generic local function;
    • deconstructions whose receiver fails a new(), unmanaged or struct constraint, or beside a Deconstruct with 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 internal Length, which stay entries. The run passes only the host file, so the internal members are seen through the public surface.

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 (DisposeAsync 2, 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 regex over these classes: 622 passed, 0 failed.
    • TransformWorkerImplicitCallPatternLayoutTests
    • TransformWorkerImplicitCallPatternTests
    • HotReloadImplicitCallPatternE2ETests
    • TransformWorkerImplicitCallTests
    • TransformWorkerImplicitCallLayoutTests
    • HotReloadImplicitCallE2ETests
    • HotReloadImplicitCallLayoutE2ETests
    • HotReloadUnpassedInternalMemberE2ETests
    • HotReloadIntroducedTypeCallsAddedMemberE2ETests
    • HotReloadObjectCreationInitializerTests
    • TransformWorkerPartialTypeTests
    • HotReloadWorkerReasonTextTests
  • Extract Class commit: TransformWorkerImplicitCallLayoutTests, HotReloadImplicitCallLayoutE2ETests, and TransformWorkerImplicitCallTests gave 80 passed.
  • Code complexity (max 15), file length (max 500), check-skill-size, and sync-tool-docs --check: no findings.

Closes #3543