Repository navigation
fix: build a set from an inline array in a query (#607, port of #583) - #609
Merged
CaffeinatedCoder merged 2 commits intoNov 30, 2026
Merged
Conversation
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)
This was referenced Nov 30, 2026
Open
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 bindsFrom(params ReadOnlySpan<T>), so the expression tree holds a conversion toReadOnlySpan<T>. EF Core's parameter evaluation cannot run that, and the query throwsInvalidOperationException(inner:ReadOnlySpan<int>violates the constraint ofFuncCallInstruction). Reproduced onrelease/10.xat 20087ed: main'sInlineSetFromArrayTests, copied unchanged, failed for every value set and range set type before the fix.Change
As on
main:ArraySpanConversionFilterPlugindeclares the array-to-span conversion not evaluatable, and the interceptor's newSpanFromRewriterbuilds an array of constants into the set throughFrom(IEnumerable<T>). It hands an array that reads a column to theIEnumerableoverload. It refuses an array of captured variables and names what to write instead.Differences from
main:### Fixedrow goes into[10.5.0](root and EF), linking release/10.x: a set built inline from an array in a query throws (port of #583) #607.compareto-null-operand-compared-as-sql-null: regenerated against this line's rewriter chain. Its defect is unchanged, and it applies and compiles.lower-bound-comparer-runs-as-sqlapplied asmainhas it and compiles.Tests
InlineSetFromArrayTestspasses 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