Skip to content

Fix string-left relational operator binding for custom types#376

Open
israellot wants to merge 5 commits into
dynamicexpresso:masterfrom
israellot:fix-string-left-relational-operator-binding
Open

Fix string-left relational operator binding for custom types#376
israellot wants to merge 5 commits into
dynamicexpresso:masterfrom
israellot:fix-string-left-relational-operator-binding

Conversation

@israellot

Copy link
Copy Markdown
Contributor

Summary

Fixes string-left relational operator binding for custom types, e.g. "10" < m, "10" <= m, "10" > m, and "10" >= m.

Root cause

Relational operators special-cased any comparison with a string left operand and routed it through string.Compare. For string vs custom type, no matching string.Compare(string, T) exists, so a null MethodInfo was passed to Expression.Call, causing ArgumentNullException.

Fix
• Use the string.Compare shortcut only for string/string comparisons.
• Let string/custom relationals use normal binary operator resolution.
• Add fallback binding through a single implicit conversion when no direct user-defined operator matches.

Tests

Added NUnit coverage for all four relational operators in both operand orders, including direct string/custom operators, implicit-conversion fallback, and equality regressions.

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.

2 participants