Skip to content

Compare awaited numbers of different types by value - #7

Open
ivank-ys wants to merge 2 commits into
yevhen:mainfrom
ivank-ys:fix-async-comparison-of-mixed-numbers
Open

ivank-ys wants to merge 2 commits into
yevhen:mainfrom
ivank-ys:fix-async-comparison-of-mixed-numbers

Conversation

@ivank-ys

Copy link
Copy Markdown

Summary

An awaited comparison of two numbers with different types fails even when the values are equal, and an ordering comparison throws. The async path receives boxed operands and compares them with Equals and Comparer.Default, which treat a boxed long and int as different types. The same check without await passes, because the compiler converts the int.

Task<long> NextId() => Task.FromResult(101L);

Assert(await NextId() == 101);
// main: Assertion failed: await NextId() == 101
//         Left:  101
//         Right: 101

Assert(await NextId() > 100);
// main: ArgumentException: Object must be of type Int64.

Two numbers now go through native C# operators, already used by the dynamic path and moved to a shared NativeOperators class in the first commit. Other values still compare with Equals, so == on a class with its own Equals keeps passing, as in the synchronous path.

Merge Danger

Reversibility: reversible

Blast Radius: user tests. Awaited comparisons of mixed number types that failed or threw now pass when the values are equal.

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.

1 participant