Skip to content

Nullable decimal comparison bug in dotnet 8.0.5 (SDK 8.0.300) #73510

@Quintinon

Description

@Quintinon

Description

There is a change in how a null valued decimal? behaves in 8.0.5 compared to previous version of the sdk/runtime.
I'm seeing the result of nullDecimalVariable == 0.00m to be equal to true in 8.0.5 (SDK 8.0.300) but was false in previous versions.

Reproduction Steps

I created a simple new console application using dotnet new console and pasted the following code into it.

decimal? v = 0.00m;
Console.WriteLine(v == decimal.Zero); // True in both 8.0.205 and 8.0.300
v = null;
Console.WriteLine(v == decimal.Zero); // False in both 8.0.205 and 8.0.300
Console.WriteLine(v == 0.00m); // False in 8.0.205 and true in 8.0.300

I also added a global.json file to control which version of the dotnet SDK it was running against. I swapped between 8.0.205 and 8.0.300 which are the two versions of 8 I have installed. 8.0.205 was installed with visual studio, and I manually installed 8.0.300 via the SDK download to reproduce this bug.
image

I was only able to reproduce this using the command line dotnet run. Running in visual studio did not reproduce this issue. It is not only occurring on my machine. We had a test failure with the same root cause as this minimal repo on our two different dedicated build machines.

Test.zip

Expected behavior

I expected null == 0.00m to return false as shown in 8.0.205
image

Actual behavior

null == 0.00m is returning true as shown in 8.0.300
image

Regression?

Yes. I tried on the previous SDK version of 8.0.205 and it works.

Known Workarounds

No response

Configuration

Dotnet 8.0.5 (SDK 8.0.300)
System Information:
Edition Windows 11 Pro
Version 23H2
Installed on ‎4/‎15/‎2024
OS build 22631.3447
Experience Windows Feature Experience Pack 1000.22688.1000.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions