Skip to content

object.Equals() in EquatableArray{T} causes an infinite loop #1119

@JamesYFC

Description

@JamesYFC

Describe the bug

The source generator project's helper struct EquatableArray will cause a stack overflow if object.Equals() is called.
This is because Equals(this, foo) will call object.Equals(), resulting in an infinite loop.
We need to call the typed version from IEquatable<T> instead.

Regression

No response

Steps to reproduce

Add this test to CommunityToolkit.Mvvm.SourceGenerators Test_SourceGeneratorsCodegen.cs to confirm:

[TestMethod]
public void EquatableArrayTest()
{
    object a = new EquatableArray<string>();
    var b = new EquatableArray<string>();

    Assert.AreEqual(a, b);
}

Before the fix, it will cause a stack overflow.

Expected behavior

You would expect the test to pass without a stack overflow.

Screenshots

No response

IDE and version

VS 2022

IDE version

No response

Nuget packages

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.4.0

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions