Skip to content

fix: fail HasValue on a null enum subject - #1046

Merged
vbreuss merged 1 commit into
mainfrom
fix/has-value-null-subject
Sep 12, 2026
Merged

vbreuss merged 1 commit into
mainfrom
fix/has-value-null-subject

Conversation

@vbreuss

@vbreuss vbreuss commented Sep 12, 2026

Copy link
Copy Markdown
Member

Convert.ToInt64(null, CultureInfo.InvariantCulture) returns 0, so a null subject was treated as an enum with the value 0: Expect.That((MyColors?)null).HasValue(0) succeeded and the corresponding DoesNotHaveValue(0) failed, while every other value behaved the other way round.

The constraint now checks the subject for null first, so HasValue always fails and DoesNotHaveValue always succeeds for a null subject, independent of the expected value.

@vbreuss vbreuss self-assigned this Sep 12, 2026
Copilot AI lite review requested due to automatic review settings September 12, 2026 14:13
@vbreuss vbreuss added the bug Something isn't working label Sep 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@vbreuss
vbreuss enabled auto-merge (squash) September 12, 2026 14:13
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

     23 files       23 suites   8m 41s ⏱️
 20 240 tests  20 238 ✅ 2 💤 0 ❌
104 651 runs  104 649 ✅ 2 💤 0 ❌

Results for commit af25a92.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.31 (8.0.31, 8.0.3126.42015), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Bool_aweXpect 250.6 ns 3.85 ns 3.61 ns 0.0415 - 696 B
Bool_FluentAssertions 242.0 ns 2.85 ns 2.66 ns 0.0567 - 952 B
Equivalency_aweXpect 316,768.6 ns 650.73 ns 576.85 ns 20.0195 0.4883 335444 B
Equivalency_FluentAssertions 2,758,850.0 ns 10,472.60 ns 9,283.69 ns 289.0625 46.8750 4841651 B
Int_GreaterThan_aweXpect 261.7 ns 1.35 ns 1.19 ns 0.0515 - 864 B
Int_GreaterThan_FluentAssertions 244.2 ns 1.17 ns 1.04 ns 0.0730 - 1224 B
ItemsCount_AtLeast_aweXpect 493.5 ns 1.83 ns 1.62 ns 0.0811 - 1360 B
ItemsCount_AtLeast_FluentAssertions 474.5 ns 5.51 ns 5.15 ns 0.1197 - 2008 B
String_aweXpect 466.1 ns 2.17 ns 2.03 ns 0.0672 - 1128 B
String_FluentAssertions 1,203.1 ns 6.80 ns 6.03 ns 0.2346 - 3944 B
StringArray_aweXpect 2,021.0 ns 15.10 ns 14.13 ns 0.1564 - 2624 B
StringArray_FluentAssertions 1,341.8 ns 5.77 ns 5.11 ns 0.2480 - 4152 B
StringArrayInAnyOrder_aweXpect 2,667.4 ns 38.32 ns 35.85 ns 0.1678 - 2816 B
StringArrayInAnyOrder_FluentAssertions 27,195.7 ns 74.90 ns 66.39 ns 1.9836 0.0610 33471 B

`Convert.ToInt64(null, CultureInfo.InvariantCulture)` returns `0`, so a `null`
subject was treated as an enum with the value `0`:
`Expect.That((MyColors?)null).HasValue(0)` succeeded and the corresponding
`DoesNotHaveValue(0)` failed, while every other value behaved the other way
round.

The constraint now checks the subject for `null` first, so `HasValue` always
fails and `DoesNotHaveValue` always succeeds for a `null` subject, independent
of the expected value.
Copilot AI review requested due to automatic review settings September 12, 2026 14:31
@vbreuss
vbreuss force-pushed the fix/has-value-null-subject branch from 30fc274 to af25a92 Compare September 12, 2026 14:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants