Skip to content

fix: build a set from an inline array in a query (#607, port of #583) - #609

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/607-inline-set-from-array-10.x
Nov 30, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/607-inline-set-from-array-10.x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #607

The port of #583 (main PR #591, commit 15c27f2), cherry-picked with -x. Added to 10.5.0 by the maintainer on 2026-11-30, as long as the bug reproduces here. It does.

Problem

Since C# 14, Int32Set.From(new[] { 1, 2 }) inside a query binds From(params ReadOnlySpan<T>), so the expression tree holds a conversion to ReadOnlySpan<T>. EF Core's parameter evaluation cannot run that, and the query throws InvalidOperationException (inner: ReadOnlySpan<int> violates the constraint of FuncCallInstruction). Reproduced on release/10.x at 20087ed: main's InlineSetFromArrayTests, copied unchanged, failed for every value set and range set type before the fix.

Change

As on main: ArraySpanConversionFilterPlugin declares the array-to-span conversion not evaluatable, and the interceptor's new SpanFromRewriter builds an array of constants into the set through From(IEnumerable<T>). It hands an array that reads a column to the IEnumerable overload. It refuses an array of captured variables and names what to write instead.

Differences from main:

Tests

InlineSetFromArrayTests passes on every type; it failed before the fix on this branch. EF 472, EF NodaTime 118 and conventions 422 pass, the seed registry checks among them.

🤖 Generated with Claude Code

Since C# 14, Int32Set.From(new[] { 1, 2 }) binds From(params
ReadOnlySpan<T>), so the expression tree holds ReadOnlySpan<T>.op_Implicit
over the array. EF Core evaluates query parameters with the LINQ
interpreter before any plugin sees the query, and the interpreter cannot
call a method that returns a ref struct, so every such query threw. EF Core
rewrites the conversion away for MemoryExtensions only.

An IEvaluatableExpressionFilterPlugin now declares the array-to-span
conversion not evaluatable (the interpreter fails on every expression that
holds one, so nothing that evaluates today changes). The call then reaches
the query interceptor, which builds an array of constants into the set
through From(IEnumerable<T>) and inlines it, as EF Core does with an inline
Parse; hands an array that reads a column to the IEnumerable overload; and
refuses an array of captured variables, whose values are bound after the
rewrite, naming the two spellings that work.

Two seed patches touched the interceptor's rewriter chain and are
refreshed against it; their defects are unchanged.

Found-By: CA
Defect-Class: SQL

Port to release/10.x (#607). The regression test failed here unchanged
before the fix, for every set type. The interceptor and the filter plugin
apply as on main; the changelog rows go into [10.5.0], linking #607; the
seed compareto-null-operand-compared-as-sql-null is regenerated against
this line's rewriter chain (lower-bound-comparer-runs-as-sql applied as
main has it). Both seeds still compile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 15c27f2)
@CaffeinatedCoder CaffeinatedCoder added this to the 10.5.0 milestone Nov 30, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference labels Nov 30, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit c6a8400 into release/10.x Nov 30, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/607-inline-set-from-array-10.x branch November 30, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities bug Something isn't working package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant