Skip to content

Core: Clean up Variant comparison operators#112459

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
Repiteo:core/variant-comparison-cleanup
Feb 17, 2026
Merged

Core: Clean up Variant comparison operators#112459
Repiteo merged 1 commit into
godotengine:masterfrom
Repiteo:core/variant-comparison-cleanup

Conversation

@Repiteo

@Repiteo Repiteo commented Nov 6, 2025

Copy link
Copy Markdown
Contributor

Cleans up the Variant comparison operations in a few ways:

  • Ensures all C++17 comparison operations exist, deriving from == and <
  • Label return values as [[nodiscard]]
  • Removed old != operator entirely

The last one in particular should've never been separate logic to begin with. I've looked at the operation outputs, and I can't find a single scenario where != and !(==) result in different outputs. I can only assume this was either once the case but has since been fixed, or the original comment was misinformed.

@Repiteo Repiteo added this to the 4.x milestone Nov 6, 2025
@Repiteo Repiteo requested a review from a team as a code owner November 6, 2025 01:30
@Ivorforce

Ivorforce commented Nov 6, 2025

Copy link
Copy Markdown
Member

The behavior of using OP_NOT_EQUAL has been used since at least 2016. I assume it was thought that using separate operators for == and != would somehow be beneficial. Otherwise, we wouldn't have a separate OP_NOT_EQUAL in the first place.

By not calling OP_NOT_EQUAL here, we'd be making a first step towards "deprecating" OP_NOT_EQUAL altogether, by not calling it from our own != operations. I think this is good, but it should be discussed.

The comment was added in #35816, cc @touilleMan

@Ivorforce Ivorforce requested a review from touilleMan November 6, 2025 09:17
@AThousandShips AThousandShips changed the title Core: Cleanup Variant comparison operators Nov 6, 2025
@touilleMan

Copy link
Copy Markdown
Member

The comment was added in #35816, cc @touilleMan

My memory is totally crumbling imperfect, but I think my rational here was to consider the OP_NOT_EQUAL operator similarly to Python __ne__. So in theory a object could overwrite how OP_NOT_EQUAL was working, and then my_custom_obj1 != my_custom_obj2 would behave differently from [my_custom_obj1] != [my_custom_obj2]

However, like @Ivorforce say, this is something that haven't materialized in the end. And I'm 100% favorable to remove OP_NOT_EQUAL and consider != is always the invert of == 👍

@Repiteo Repiteo modified the milestones: 4.x, 4.7 Feb 17, 2026
@Repiteo Repiteo merged commit ff90854 into godotengine:master Feb 17, 2026
20 checks passed
@Repiteo Repiteo deleted the core/variant-comparison-cleanup branch February 17, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment