Skip to content

fix(reactive): cast awaited command calls to their return type before awaiting - #3228

Merged
kazo0 merged 3 commits into
mainfrom
dev/steve/mvux-cast-await
Oct 14, 2026
Merged

kazo0 merged 3 commits into
mainfrom
dev/steve/mvux-cast-await

Conversation

@kazo0

@kazo0 kazo0 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #3227

PR Type

  • Bugfix

What is the current behavior?

In __Reactive_BindableInitializeForUpdatedModel the model is dynamic, so each awaitable command's generated Execute lambda awaits a dynamic value:

await model.Increment(reactive_ct);

Roslyn's EnC crashes on edits that add or replace such a lambda while another lambda captures the dynamic local (dotnet/roslyn#86045). Changing a command's parameters while the app runs then breaks Hot Reload: that edit and every later one fail until the app restarts.

What is the new behavior?

When the method is awaitable, the generated call is cast to the method's declared return type before awaiting:

await ((global::System.Threading.Tasks.ValueTask)model.Increment(reactive_ct));
await ((global::System.Threading.Tasks.ValueTask)model.Add(step, ct));   // with a command parameter
  • What stays the same: the call is still dynamic, so it binds to the updated model. Only the await is on a static type.
  • Return types: the type is formatted with the generator's existing ToFullString(), so Task, ValueTask, Task<T>, ValueTask<T> and custom awaitables with an instance GetAwaiter all work with no special case.
  • Extension GetAwaiter: when the return type is awaitable only through an extension GetAwaiter, the generated file adds using static global::<ExtensionClass>; so the static await binds. This also fixes the constructor path, which already failed with CS1061 whenever the extension's namespace didn't enclose the model's. It imports the class and not its namespace because the generated file uses unqualified Type/Task, which a user namespace could make ambiguous. Only extensions declared in source are detected (IsAwaitable uses Compilation.GetSymbolsWithName), as before.
  • Unchanged cases: non-awaitable methods, and async void (which can't be cast to void).
  • The constructor path shares GetInitialization() and gets an identity cast. Limiting the cast to the dynamic path would mean threading a flag through every mapped member.
  • Nothing else needed changing: command Execute is the only place the generator emits await, since feeds already cast model.X to IFeed<...>. ViewModelGenTool_2 uses the same command code, so it gets the fix too.
  • Revert note: a comment at the cast cites EnC: adding an async lambda that awaits a dynamic call throws InvalidOperationException in DeltaMetadataWriter.GetFieldDefinitionHandle dotnet/roslyn#86045, to be removed once Roslyn is fixed.

PR Checklist

  • Unit tests for the changes have been added: Given_FeedsGenerator_Commands runs the generator in memory on a model with these commands:

    • ValueTask, ValueTask with a parameter, Task, ValueTask<int>, Task<string?> and void.
    • a custom awaitable whose extension GetAwaiter lives in a namespace unrelated to the model's (asserts the using static).

    It asserts:

    • each cast appears on both paths;
    • no await model. remains;
    • the generated code compiles.

    It fails before the fix. The test project now references the generator project. Given_FeedsMockGenerator's fixture compilation leaves out the generator dll, whose copies of the public attributes otherwise caused CS0433 errors.

  • Uno.HotTesting.Reactive.Tests: 36/36 passed. Uno.Extensions.Reactive.Tests: 1469 passed, 19 skipped.

  • Contains NO breaking changes

  • Associated with an issue (GitHub or internal)

Other information

Verified end to end. I swapped the patched generator into Uno.Extensions.Reactive 8.0.0-dev.76, whose generator inputs are unchanged since then. I ran it on a recommended-preset MVUX app on Skia desktop with a fresh DevServer:

  1. Add a state: applied.
  2. Change Increment(CancellationToken) to Increment(int step, CancellationToken): applied (InternalError before this change).
  3. Edit the command's body: applied.

Related: unoplatform/uno#25418, where the DevServer reports this class of compiler crash as a rude edit and not as a stuck InternalError.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WjQPjTHecnxjgcqBhM8z3e

… awaiting

In __Reactive_BindableInitializeForUpdatedModel the model is dynamic, so each awaitable command's Execute lambda awaited a dynamic value. Roslyn EnC crashes on edits that add or replace such a lambda (dotnet/roslyn#86045), which wedged Hot Reload until the app restarted. The call stays dynamic so it still binds to the updated model; only the await is on the declared return type. The constructor path shares this code and gets an identity cast.

Fixes #3227

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WjQPjTHecnxjgcqBhM8z3e
kazo0 and others added 2 commits October 14, 2026 14:53
- A command method returning a type awaitable only through an extension `GetAwaiter` now gets a `using static` for that extension's class in the generated view model
- Without it, the statically typed await failed to compile with CS1061 on the constructor path whenever the extension's namespace didn't enclose the model's, and the dynamic Hot Reload path could never bind it
- Import the declaring static class rather than its namespace, so the generated file's unqualified `Type`/`Task` can't become ambiguous
- Add Given_FeedsGenerator_Commands case with the awaitable in an unrelated namespace (fails before the fix)

Refs #3227

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JwBEb6W93fTZzohP7V6ZYp
…wait

# Conflicts:
#	src/Uno.HotTesting.Reactive.Tests/Given_FeedsMockGenerator.cs
@kazo0
kazo0 enabled auto-merge October 14, 2026 19:33
@kazo0
kazo0 disabled auto-merge October 14, 2026 20:41
@kazo0
kazo0 merged commit 72c5937 into main Oct 14, 2026
25 of 26 checks passed
@kazo0
kazo0 deleted the dev/steve/mvux-cast-await branch October 14, 2026 20:41
agneszitte added a commit that referenced this pull request Nov 3, 2026
… awaiting (backport #3228)

- Backport of #3228 to servicing/7.4, with its Given_FeedsGenerator_Commands test
- Uno.HotTesting.Reactive.Tests.csproj: keeps 7.4's System.Collections.Immutable reference, which sat next to the comment #3228 updates

Co-Authored-By: Claude Opus 5.5 <[email protected]>
agneszitte added a commit that referenced this pull request Nov 3, 2026
…6.7-sr3

fix: get servicing/7.4 ready for 6.7 SR3 (backport #3228, #3231, #3235, #3249, #3254, #3259; Uno floor 6.7.65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HR][MVUX] Generated command lambdas await a dynamic value, which crashes Roslyn EnC; cast the call before awaiting

1 participant