Skip to content

Return false for type-mismatched comparison operands#1017

Merged
jnunemaker merged 1 commit into
mainfrom
comparison-type-mismatch-error
Jul 8, 2026
Merged

Return false for type-mismatched comparison operands#1017
jnunemaker merged 1 commit into
mainfrom
comparison-type-mismatch-error

Conversation

@jnunemaker

Copy link
Copy Markdown
Collaborator

Comparison expressions (greater_than, less_than, and their _or_equal_to variants) only guarded operands with respond_to?(operator), which confirms both sides respond to >/< but not that they're type-compatible. Because property values commonly arrive as strings from JSON, comparing something like "25" >= 21 raised ArgumentError out of Feature#enabled?, crashing the entire flag check instead of returning false. This rescues ArgumentError in Comparable.call and treats a failed comparison as false, consistent with how missing/nil properties already behave. Added specs covering type-mismatched operands (both orderings) for all four comparison expressions.

🤖 Generated with Claude Code

Comparison expressions (greater_than, less_than, and their _or_equal_to
variants) guarded operands with respond_to?(operator), which confirms
both sides respond to >/< but not that they are type-compatible. Since
property values commonly arrive as strings from JSON, comparing
"25" >= 21 raised ArgumentError out of Feature#enabled?, crashing the
whole flag check instead of returning false.

Rescue ArgumentError and treat a failed comparison as false, consistent
with how missing/nil properties already behave.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jnunemaker jnunemaker merged commit 983505c into main Jul 8, 2026
46 checks passed
@jnunemaker jnunemaker deleted the comparison-type-mismatch-error branch July 8, 2026 20:21
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.

1 participant