Skip to content

Fix #2607: SortByColumns order-table overload fails with Float/Decimal type mixing#3061

Open
anderson-joyle wants to merge 2 commits into
mainfrom
a-team/issue-2607
Open

Fix #2607: SortByColumns order-table overload fails with Float/Decimal type mixing#3061
anderson-joyle wants to merge 2 commits into
mainfrom
a-team/issue-2607

Conversation

@anderson-joyle
Copy link
Copy Markdown
Contributor

Summary

Fixes #2607SortByColumns([{A:Float(1)}, ...], "A", [3,2,1]) produced a compile-time type error in V1 mode and, when it did compile, an incorrect sort order at runtime.

Root cause — two independent bugs

Bug 1 (compile-time, SortByColumns.cs): CheckTypesOrderTableOverload called DType.Accepts(exact: true), which rejects Number/Decimal mixing under V1 rules. Float columns with a Decimal order table produced a binding error.

Bug 2 (runtime, LibraryTable.cs): TryGetPrimitiveValue returns System.Double for NumberValue and System.Decimal for DecimalValue. List<object>.IndexOf uses object.Equals, which always returns false for double vs decimal. Every Float row was placed at the end of the sort output.

Fix

  • Binder: Added isNumericCoercionAllowed guard — when both the column type and order-table value type satisfy IsNumeric, the Accepts() check is skipped.
  • Runtime: Added NormalizeNumericPrimitive() that converts decimaldouble, applied both when building the order-table lookup list and when extracting column values during sort.

Files changed:

  • SortByColumns.cs — numeric coercion guard in CheckTypesOrderTableOverload
  • LibraryTable.csNormalizeNumericPrimitive() helper + two call sites in SortByColumnsOrderTable
  • 3 new expression test cases (string-literal, dynamic-string, and identifier column name forms)
  • .Net7.0 TFMs bumped to net8.0 (net7.0 EOL; may need reverting for CI)

Confidence: 9 / 10

Targeted SortByColumnsOrderTable_ColumnNamesAsIdentifiersEnabled tests (212 cases including 3 new) and full FileExpressionEvaluationTests suite (63,240 passed, 0 failed, 318 skipped). Minor known gap: reverse case (Decimal source + Float order table) not explicitly tested, but normalization is symmetric.

Test plan

  • CI passes on this branch
  • New expression tests in SortByColumnsOrderTable_ColumnNamesAsIdentifiersEnabled*.txt pass
  • No regressions in existing SortByColumns/SortByColumnsOrderTable tests

🤖 Generated with Claude Code

…l type mixing

Two bugs in the SortByColumns order-table overload when a Float (Number/double) column
is used with a Decimal order table:

Bug 1 (compile-time): CheckTypesOrderTableOverload used DType.Accepts with exact:true,
which rejects Number/Decimal mixing under V1 rules. Fix: skip the Accepts check when
both the column type and order-table value type are numeric (IsNumeric).

Bug 2 (runtime): TryGetPrimitiveValue returns System.Double for NumberValue and
System.Decimal for DecimalValue. List<object>.IndexOf uses object.Equals, which returns
false for double vs decimal, so every Float row was placed at the end. Fix: add
NormalizeNumericPrimitive() that converts decimal to double, applied when building the
order-table lookup list and when extracting column values during the sort.

Also bumps .Net7.0 test project TFMs to net8.0 (net7.0 EOL on this machine).

Fixes #2607
@anderson-joyle anderson-joyle requested review from a team as code owners May 1, 2026 03:48
@jas-valgotar
Copy link
Copy Markdown
Contributor

✅ No public API change.

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.

SortByColumns( [Float(1), Float(3), Float(2)], Value, [3,2,1] ) does not work

2 participants