Skip to content

Fix AttributedScopeStack equality type check#111

Merged
danipen merged 3 commits intomasterfrom
copilot/fix-equals-method-logic
Feb 4, 2026
Merged

Fix AttributedScopeStack equality type check#111
danipen merged 3 commits intomasterfrom
copilot/fix-equals-method-logic

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

AttributedScopeStack.Equals was rejecting comparisons with other AttributedScopeStack instances, so equality always returned false and could throw on unrelated types. This change restores correct type checking and adds focused equality coverage.

  • Equality fix

    • Correct the null/type guard so AttributedScopeStack comparisons proceed.
  • Tests

    • Add NUnit coverage for equal/unequal stacks, null, and different-type inputs.
public override bool Equals(object other)
{
    if (other == null || !(other is AttributedScopeStack))
        return false;

    return Equals(this, (AttributedScopeStack)other);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrect logic in AttributedScopeStack.Equals() method</issue_title>
<issue_description>The Equals(object other) override in AttributedScopeStack contains a logic error that causes it to always return false when comparing two AttributedScopeStack instances, breaking equality comparison.

Current Behavior

public override bool Equals(object other)
{
    if (other == null || (other is AttributedScopeStack))
        return false;
    return Equals(this, (AttributedScopeStack)other);
}

Returns false when other is an AttributedScopeStack (incorrect)
Would attempt to cast and compare when other is not an AttributedScopeStack, causing InvalidCastException

Expected Behavior
The method should return false when other is null or not an AttributedScopeStack, and perform equality comparison when it is.
Proposed Fix

public override bool Equals(object other)
{
    if (other == null || !(other is AttributedScopeStack))
        return false;
    return Equals(this, (AttributedScopeStack)other);
}
```</issue_description>

<agent_instructions>Add a unit test if possible for it</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 4, 2026 09:10
Co-authored-by: danipen <501613+danipen@users.noreply.github.com>
Co-authored-by: danipen <501613+danipen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix logic in AttributedScopeStack.Equals() method Fix AttributedScopeStack equality type check Feb 4, 2026
Copilot AI requested a review from danipen February 4, 2026 09:12
Copy link
Owner

@danipen danipen left a comment

Choose a reason for hiding this comment

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

LGTM

@danipen danipen marked this pull request as ready for review February 4, 2026 09:17
@danipen danipen merged commit 9d8694d into master Feb 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect logic in AttributedScopeStack.Equals() method

2 participants