Skip to content

test: sweep the EF translators for operands mapped as a type their overload does not declare (#295) - #432

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
test/295-translator-name-dispatch
Oct 25, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
test/295-translator-name-dispatch

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #295

Part of 10.3.0 (#408): it goes ahead of #405, #406 and #191, so the translator arms they add are written under the sweep. main first, then cherry-picked into release/10.x.

Problem

The EF translators recognize an overload by its name and argument count, and some then chose an operand's mapping from what the operand was not:

  • RangeSet calls (Operand(), AsSet()): anything that wasn't the multirange or the element was mapped as a range.
  • Value set calls: the second operand of every two-argument arm was mapped as a set, and the element of Contains/Remove was assumed.
  • Factories: CreateFinite, CreateUnboundedStart and CreateUnboundedEnd were matched by name and argument count, with their bounds assumed to be the element type.
  • Aggregates: any source that wasn't a sequence of multiranges was mapped as ranges.

Every answer was right today, because only the overloads those arms were written for exist. But an overload added later with another operand type would have been translated as one of them. A RangeSet.Contains(StringSet) became @> over a value set mapped as a range, with no error and no failing test. That's the receiver-shaped dispatch trap one layer up, and the shape of dotnet/efcore#39329.

Change

  • TranslatorDispatchSweepTests (conventions, no database): every public query member (QueryMembers) over every discovered range and value set type is handed to the translator providers of a real context (UseValueRangesNodaTime(), so EF Core's, Npgsql's and both plugins' translators run in their real order), with one operand per declared parameter type. A translation must map each operand as its declared type and answer the member's own type, and a translator that throws fails the sweep. It also fails if it reaches none of the plugin's six areas, so it can't pass by inspecting nothing.
  • The translators map an operand from the type its overload declares, and throw MissingArm (an UnreachableException naming the overload and the operand type) for any other. Declining wouldn't be enough, because EF Core's own translators match by name too, as its collection Contains took RangeSet.Contains (10.x: RangeSet.Contains throws ArgumentException on the EF Core 10 patch that carries dotnet/efcore#37081 #288).
    • ValueRangesMethodCallTranslator: RangeSet operands go by parameter type, and the three factories are recognized by their whole signature, with any other overload of those names refused. The set-operand arms' unreachable _ now throws instead of declining.
    • ValueSetsMethodCallTranslator: the set operands (as the set, IValueSet<T> or IValueSetFactory<TSet, T>) and the element go by parameter type.
    • ValueRangesAggregateMethodCallTranslator: the source must be a sequence of the range or of its multirange.
    • ValueSetsMemberTranslator: Count and IsEmpty are recognized by name and type, and any other declines, since a member has no operand to mis-map.
  • QueryMembers.Close and Mentions: moved from TranslationSupportProbeTests so the probe and the sweep share one way of closing a member over a type.
  • Registered in oracles.json (silent-default), described in docs/oracles.md, with a rule in AGENTS.md.

No answer changes for any existing overload, and no package's public API changes. So there's no changelog row.

Not here: the query interceptor's RangeSetContains.Equivalent has the same fallback, sending any other one-argument Contains to the value overload. That's #320 (and its 10.x port #326), which gets its own PR. The sweep calls the translators directly, so it doesn't reach the interceptor.

Tests

  • The sweep on the fixed translators: passes, and no existing overload hits MissingArm.
  • Seed rangeset-overload-without-translator-arm.patch (adds RangeSet.Contains(StringSet) in core):
    • Without the fix, the sweep fails with "an operand declared StringSet is mapped as daterange (DateRange)" on every range type.
    • With the fix, it fails with the refusal: "RangeSet<DateRange, DateOnly>.Contains(StringSet) has no translation for an operand of type StringSet".
    • Either way, all 300 EF translation tests still pass with the seed applied. So the sweep fails before any translation test does, as Sweep the EF translators for name-only dispatch and default operand classification #295 asks.
  • MissingArmTests (EF translation tests): each translator is handed an overload that doesn't exist, built as a MethodInfo/PropertyInfo with the declaring type, name and parameters a later one would have: RangeSet.Contains/Union(StringSet), DateRange.CreateFinite(int, int, bool, bool), ValueSetExtensions.Overlaps(StringSet, Int32Set) and Contains(StringSet, int), RangeAgg(IEnumerable<IRange<DateOnly>>), and a long Count on StringSet. 7/7 pass. With the four translators reverted to main, all 7 fail: "no exception was thrown", and a non-null translation for Count.
  • Full runs, locally on the .NET 11 RC2 SDK: conventions 417/417, EF translation 307/307, NodaTime EF translation 83/83, core 1,399/1,399, NodaTime 239/239, ASP.NET Core 92/92, integration on PostgreSQL 16 306/306.

🤖 Generated with Claude Code

…erload does not declare (#295)

The translators recognized an overload by its name and argument count, and
mapped an operand from what it was not: a RangeSet operand that was neither
the multirange nor the element became a range, a value set call's second
operand a set, a factory's bounds the element, an aggregate's source ranges.
Every answer was right for the overloads that exist, but one added later
with another operand type would have been translated as one of them, without
an error: RangeSet.Contains(StringSet) became @> over a value set mapped as
a range.

TranslatorDispatchSweepTests (conventions, no database) hands every public
query member over every discovered type to the translator providers of a
real context, one operand per declared parameter type, and requires each
operand mapped as its declared type and the member's own result type. The
translators now map an operand from its declared parameter type and throw
MissingArm, naming the overload, for any other; MissingArmTests holds each
arm with an overload that does not exist. QueryMembers.Close moves from the
translation-support probe so both share it.

Found-By: RV
Defect-Class: SQL
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.3.0 milestone Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder added tests Adds or changes tests only (oracles, harnesses); no library code area/ranges Range unions, variants and the shape engines area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime labels Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 9caa202 into main Oct 25, 2026
14 of 17 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the test/295-translator-name-dispatch branch October 25, 2026 13:49
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/ranges Range unions, variants and the shape engines area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime tests Adds or changes tests only (oracles, harnesses); no library code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sweep the EF translators for name-only dispatch and default operand classification

1 participant