Skip to content

Inconsistent behavior in NET7 String.Equals #78169

Closed
@recumbented

Description

@recumbented

Description

NET7 String.Equals shows inconsistent behavior in differences of target platform bitness, and Release or Debug.

const String v1 = "鉄";
var v2 = v1;
Console.WriteLine($"{v1 == v2}, {v1.Equals(v2, StringComparison.Ordinal)}, {v1.Equals(v2,StringComparison.OrdinalIgnoreCase)}");

foreach (var _ in Array.Empty<Object>())
{
    //Do nothing
}
dotnet run -r win-x86 --no-self-contained -c Release
False, False, True

dotnet run -r win-x64 --no-self-contained -c Release
True, True, True

dotnet run -r win-x86 --no-self-contained -c Debug
True, True, True

dotnet run -r win-x64 --no-self-contained -c Debug
True, True, True

In addition, if you just comment out foreach, output will change.

const String v1 = "鉄";
var v2 = v1;
Console.WriteLine($"{v1 == v2}, {v1.Equals(v2, StringComparison.Ordinal)}, {v1.Equals(v2,StringComparison.OrdinalIgnoreCase)}");

// foreach (var _ in Array.Empty<Object>())
{
    //Do nothing
}
dotnet run -r win-x86 --no-self-contained -c Release
True, True, True

Configuration

SDK 7.0.100
x86
Same behavior in local windows machine, Azure App Service (Windows)

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions