Skip to content

Conversation

@yusuftor
Copy link
Contributor

@yusuftor yusuftor commented Jan 21, 2026

Summary

  • Simplifies string normalization by not converting numeric strings to numbers at all
  • Only "true" and "false" strings are converted to booleans
  • All other strings (including numeric strings like "5690201") stay as strings
  • Removes the complex extract_string_compared_variables mechanism in favor of this simpler approach

What was the issue?

device.appBuildString == "5690201" was returning false even when device.appBuildString was the string "5690201". The previous fix tried to selectively skip normalization using extract_string_compared_variables, but this was complex and had edge cases.

The fix

Instead of selective normalization, we now simply don't convert numeric strings to numbers. Quoted strings stay as strings - if users want a number, they write it without quotes.

Test plan

  • Run cargo test --lib - all 107 tests pass
  • Verify device.appBuildString == "5690201" returns true when variable is string "5690201"
  • Verify version string comparisons still work (device.appVersionPadded > "007.003.001")
  • Verify "true"/"false" strings are still converted to booleans

🤖 Generated with Claude Code

This is a simpler fix for the string comparison issues. Instead of the
complex `extract_string_compared_variables` mechanism that tried to
selectively skip normalization, we now simply don't convert numeric
strings to numbers at all.

Changes:
- Modified `normalize_variables` to only convert "true"/"false" strings
  to booleans, leaving all other strings as strings
- Modified `normalize_ast_variables` similarly for AST atoms
- Removed `extract_string_compared_variables` and related functions
- Removed `is_number` and `is_atom_number` functions
- Removed `skip_normalization` parameter threading through the code

This fixes:
- `device.appBuildString == "5690201"` now works correctly
- `device.appVersionPadded > "007.003.001"` still works for version comparisons
- Version strings like "009.000" stay as strings for lexicographic comparison

The fix is simpler and more predictable: quoted strings stay as strings.
If users want a number, they should write it without quotes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yusuftor yusuftor force-pushed the feature/fix-string-to-int branch from 9675c37 to 106601f Compare January 21, 2026 15:43
@yusuftor yusuftor changed the title Fix string literal normalization in expressions Simplify string normalization - don't convert numeric strings to numbers Jan 21, 2026
@yusuftor yusuftor requested a review from ianrumac January 21, 2026 15:49
When comparing a value to a numeric string (e.g., "1" or "1.23"),
the comparison now matches both the string and numeric representations.

For example:
- `x == "1"` becomes `(x == "1") || (x == 1)`
- `x != "1"` becomes `(x != "1") && (x != 1)`

This allows:
- `1 == "1"` → true (int matches numeric string)
- `1.23 == "1.23"` → true (float matches numeric string)
- `"5690201" == "5690201"` → true (string matches string)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yusuftor
Copy link
Contributor Author

Updated: Type coercion for numeric string comparisons

This commit adds type coercion for equality comparisons with numeric strings.

What changed?

When comparing with a numeric string (like "1" or "1.23"), the AST transformation now creates an expression that matches both the string and numeric representations:

x == "1"   →  (x == "1") || (x == 1)
x \!= "1"   →  (x \!= "1") && (x \!= 1)

Why?

Two scenarios now work correctly:

  1. device.appBuildString == "5690201" where appBuildString is a stringtrue
  2. device.some_key == "1" where some_key is an inttrue

Test results

  • All 107 tests pass
  • 1 == "1"true (int matches numeric string)
  • 1.23 == "1.23"true (float matches numeric string)
  • "5690201" == "5690201"true (string matches string)

@yusuftor yusuftor merged commit d12ecd7 into master Jan 23, 2026
1 check 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.

3 participants