Skip to content

Fix AttributedScopeStack equality type check#111

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

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

Conversation

Copilot AI commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

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

@danipen danipen left a comment

Copy link
Copy Markdown
Owner

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
fuzzzerd pushed a commit to fuzzzerd/SharpFM that referenced this pull request Jun 30, 2026
Updated
[TextMateSharp.Grammars](https://github.com/danipen/TextMateSharp) from
2.0.3 to 2.0.4.

<details>
<summary>Release notes</summary>

_Sourced from [TextMateSharp.Grammars's
releases](https://github.com/danipen/TextMateSharp/releases)._

## 2.0.4

## What's Changed
* Fix AttributedScopeStack equality type check by @​Copilot in
danipen/TextMateSharp#111
* Fix multiple race conditions in TMModel #​109 by @​udlose in
danipen/TextMateSharp#114
* Performance/reduce allocations, increase test coverage, configure code
coverage, fix race condition by @​udlose in
danipen/TextMateSharp#115
* Fix #​116 and Performance/reduce allocations by @​udlose in
danipen/TextMateSharp#121
* [Breaking]: Fixes #​117 - Fix typo: rename PushAtributed to
PushAttributed by @​udlose in
danipen/TextMateSharp#122
* [Breaking]: Part 1 of 2 Restrict visibility, add immutability,
refactor internals… by @​udlose in
danipen/TextMateSharp#124
* Part 2 of 3 for #​123 - Fix sealed & visibility issues part2 by
@​udlose in danipen/TextMateSharp#125
* Update onigwrap to 1.0.11 by @​pauldumais in
danipen/TextMateSharp#127
* Add x86 assembly grammar by @​RysteQ in
danipen/TextMateSharp#129
* Update CI workflows to use .NET 8 SDK by @​danipen in
danipen/TextMateSharp#130

## New Contributors
* @​Copilot made their first contribution in
danipen/TextMateSharp#111
* @​udlose made their first contribution in
danipen/TextMateSharp#114
* @​pauldumais made their first contribution in
danipen/TextMateSharp#127
* @​RysteQ made their first contribution in
danipen/TextMateSharp#129

**Full Changelog**:
danipen/TextMateSharp@v2.0.3...v2.0.4

Commits viewable in [compare
view](danipen/TextMateSharp@v2.0.3...v2.0.4).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=TextMateSharp.Grammars&package-manager=nuget&previous-version=2.0.3&new-version=2.0.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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