Skip to content

Fix AmbiguousMatchException for default ValueTask<T> of reference types - #231

Merged
kzu merged 1 commit into
mainfrom
fix/valuetask-reference-default
Sep 29, 2026
Merged

kzu merged 1 commit into
mainfrom
fix/valuetask-reference-default

Conversation

@kzu

@kzu kzu commented Sep 29, 2026

Copy link
Copy Markdown
Member

DefaultValueProvider threw AmbiguousMatchException when asked for a default ValueTask<T> where T is a reference type, such as ValueTask<string>.

The default result is null, and Activator.CreateInstance can't choose between the ValueTask<T>(T) and ValueTask<T>(Task<T>) constructors for a null argument. The provider now binds the ValueTask<T>(T) constructor explicitly.

Added DefaultForValueTaskOfReferenceTypeIsCompleted, which failed with the exception before the fix. All 173 tests pass.

A null default result matched both the ValueTask<T>(T) and ValueTask<T>(Task<T>) constructors, so Activator.CreateInstance threw for types like ValueTask<string>.
@kzu kzu added the bug Something isn't working label Sep 29, 2026
@kzu
kzu merged commit d9593c9 into main Sep 29, 2026
6 checks passed
@kzu
kzu deleted the fix/valuetask-reference-default branch September 29, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant