Skip to content

Inconsistent behavior in NET7 String.Equals #78169

Closed

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)

Activity

  1. transferred this issue fromdotnet/coreon Nov 10, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 10, 2022
  3. JulieLeeMSFT commented on Nov 10, 2022

    @JulieLeeMSFT
    Member

    CC @dotnet/jit-contrib.

  4. self-assigned this
    on Nov 10, 2022
  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 10, 2022
  6. EgorBo commented on Nov 10, 2022

    @EgorBo
    Member

    @recumbented thank you so much for the report, this exposed a bug in the codegen for single-char strings + Equals/StartsWith

  7. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 10, 2022
  8. added this to the 7.0.x milestone on Nov 10, 2022
  9. modified the milestones: 7.0.x, 8.0.0 on Nov 10, 2022
  10. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 11, 2022
  11. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 11, 2022
  12. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 14, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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