diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e891549f..76ca5b30 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -200,7 +200,8 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 with: - dotnet-version: 10.0.x + dotnet-version: 11.0.x + dotnet-quality: preview # Publishes exactly what was verified — the packages are not rebuilt here. - name: Download packages @@ -233,7 +234,7 @@ jobs: # are reported and skipped instead of failing the job. Pushes are not atomic across packages, # so retry with "Re-run failed jobs" on the same run: that logs in afresh (the temporary key # expires an hour after login) and pushes the same verified artifact. A fresh run rebuilds — - # from the same commit, since release tags are immutable, but with whatever SDK 10.0.x is + # from the same commit, since release tags are immutable, but with whatever SDK 11.0.x is # then, so the remaining packages would not be the ones verified with those already pushed. - name: Push to NuGet env: diff --git a/AGENTS.md b/AGENTS.md index 2923c134..68c4b7d0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,12 +3,12 @@ This file is the canonical agent guide. `CLAUDE.md` only imports it (`@AGENTS.md`), so Claude Code and every other agent read the same rules. Edit this file, never `CLAUDE.md`. -In-memory range and multirange types for .NET 10, mirroring PostgreSQL's six built-in range domains (`int4range`, `int8range`, `numrange`, `daterange`, `tsrange`, `tstzrange`) plus two v5 additions: `TimeRange` over `TimeOnly` (maps to the custom `timerange` type — needs `HasPostgresRange` + `EnableUnmappedTypes` on the EF side) and, in the NodaTime satellite, `YearMonthRange` over `YearMonth` (stored as a month-aligned `daterange`). Since 10.0.0, `Float64Range` and `Float32Range` cover finite `double` and `float` (the custom `float8range` and `float4range`, set up like `timerange`), with `Float64Set`/`Float32Set` and their arities on `double precision[]`/`real[]`. Each range type is a discriminated union of five sealed variants with exhaustive pattern matching. +In-memory range and multirange types for .NET 11 on `main` (the 11 line; `release/10.x` stays on .NET 10), mirroring PostgreSQL's six built-in range domains (`int4range`, `int8range`, `numrange`, `daterange`, `tsrange`, `tstzrange`) plus two v5 additions: `TimeRange` over `TimeOnly` (maps to the custom `timerange` type — needs `HasPostgresRange` + `EnableUnmappedTypes` on the EF side) and, in the NodaTime satellite, `YearMonthRange` over `YearMonth` (stored as a month-aligned `daterange`). Since 10.0.0, `Float64Range` and `Float32Range` cover finite `double` and `float` (the custom `float8range` and `float4range`, set up like `timerange`), with `Float64Set`/`Float32Set` and their arities on `double precision[]`/`real[]`. Each range type is a discriminated union of five sealed variants with exhaustive pattern matching. Since v6 there is a second type family: **value sets** (`Sets/`) — immutable, canonical (deduplicated, sorted, no nulls) sets of scalar values stored as native PostgreSQL arrays (`StringSet`/`text[]`, `GuidSet`/`uuid[]`, …), plus a validated-wrapper arity for every family (`StringSet` … `DateTimeOffsetSet`, and five more in the NodaTime satellite) constrained only on BCL interfaces. EF maps them as scalars with plugin-owned mappings and translators (`@>`, `&&`, `<@`, `cardinality`, `array_cat`, `array_remove`) — never through EF's primitive-collection machinery. `Intersect`/`Except`/`Add` are deliberately client-side only: PostgreSQL's array type has no intersection, difference, or sorted insert. ## Stack -.NET 10 · C# 14 (extension methods) · MSTest 4.x · EF Core + Npgsql (PostgreSQL bridge) +.NET 11 (`main`; `release/10.x` is .NET 10) · C# 14 (extension methods) · MSTest 4.x · EF Core 11 + Npgsql (PostgreSQL bridge) ## Structure Shipping projects live under `src/`, test projects under `test/`. Never hard-code a positional @@ -23,13 +23,13 @@ so moving a project cannot silently retarget a test. - `test/CodoMetis.ValueRanges.NodaTime.Tests/` — NodaTime satellite unit tests - `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/` — EF Core SQL translation tests (no database) - `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime.Tests/` — NodaTime EF translation tests (no database) -- `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/` — Live PostgreSQL via Testcontainers (needs Docker; Inconclusive without, but hard failure under CI=true). The shared container runs `VALUERANGES_POSTGRES_IMAGE`, default `postgres:16-alpine` (the 10.x floor); CI runs both integration projects on 16 and 18, and a server below 16 fails every test (`PostgresServer.cs`). Covers BCL and NodaTime types. Authority on PostgreSQL semantics — run when changing translations or range algebra. `CapturedCollectionProbeTests` sends every discovered range and set type as a captured collection (`Contains`, `Any`, `Count`); it links `RangeProbes` and `SetProbes` from the conventions project rather than copying them. `ComplexIndexesCrossTests` holds this package's columns under `EFCore.ComplexIndexes.PostgreSQL`'s temporal and exclusion constraints and GiST indexes on PostgreSQL 16 and 18 (containers of its own) through a test-only reference; neither shipping package references the other +- `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/` — Live PostgreSQL via Testcontainers (needs Docker; Inconclusive without, but hard failure under CI=true). The shared container runs `VALUERANGES_POSTGRES_IMAGE`, default `postgres:16-alpine` (the 10.x floor); CI runs both integration projects on 16 and 18, and a server below 16 fails every test (`PostgresServer.cs`). Covers BCL and NodaTime types. Authority on PostgreSQL semantics — run when changing translations or range algebra. `CapturedCollectionProbeTests` sends every discovered range and set type as a captured collection (`Contains`, `Any`, `Count`); it links `RangeProbes` and `SetProbes` from the conventions project rather than copying them. `ComplexIndexesCrossTests` holds this package's columns under `EFCore.ComplexIndexes.PostgreSQL`'s temporal and exclusion constraints and GiST indexes on PostgreSQL 16 and 18 (containers of its own) through a test-only reference; neither shipping package references the other. Off on the 11 line (the reference and the file are conditioned on `net10.0`) until ComplexIndexes ships its own 11 preview, CaffeinatedCoder/EFCore.ComplexIndexes#38; its #42 turns them back on - `test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/` — The same live layer for configuration that is per process: its runtimeconfig sets `Npgsql.DisableDateTimeInfinityConversions`, which Npgsql and the plugin each read once, so it cannot be flipped inside the other project's run. Holds the temporal store rule at the extremes with the conversion off. Own container; CI's integration job runs every `test/*IntegrationTests/` - `test/CodoMetis.ValueRanges.AspNetCore.Tests/` — Host-level behaviour with no ValueRanges registration: configuration binding (`TypeConverter`), MVC and minimal-API binding and JSON bodies via `TestServer`, and the documented OpenAPI schema transformer (`ValueRangesSchemaTransformer.cs`), which `docs/serialization.md` must carry verbatim — edit the test copy, then the doc. `HostCultureProbeTests` binds every discovered type (core and NodaTime) through both hosts under four request cultures; it links `RangeProbes`, `SetProbes`, `WrapperElements` and `Reflect` from the conventions project rather than copying them - `test/CodoMetis.ValueRanges.Conventions.Tests/` — Repo-level conventions: changelog consistency and form, packaging metadata, release wiring, the SECURITY.md supported-versions table, value set contract compliance, EF mapping parity, the default JSON contract. Everything is discovered (projects by globbing `src/`, types by reflection), so adding a package or a type needs no edit here - `test/oracles/` — The bug-finding system (`docs/oracles.md`): `claims.json` quotes every promise the consumer-facing docs make and names the test that holds it (empty `heldBy` is the worklist); `oracles.json` registers the sweep classes; `seeds/*.patch` plant one defect each in `src/` that the named oracles were shown to catch; `surface-waivers.json` names the public members no claim covers, with the reason; `candidates.json` holds disagreements found but not fixed, keyed to issues; `postgres-surface.json` holds every PostgreSQL range, multirange and array operator and function (one entry per row of `postgres-surface.catalog.txt`, the raw `pg_operator`/`pg_proc` listing) with the member that mirrors it, the translation a test asserts, or a waiver or issue; `CloneSweep.cs` is the clone-divergence sweep over the hand-copied type families (sets, arities, ranges, EF registrations), and `clone-waivers.json` explains every divergence it finds between siblings that is right as it is. `Oracle*Tests` and `CloneDivergenceTests` in the conventions project hold all of it consistent in CI without building; `dotnet run tools/oracles.cs seeds` re-proves locally that every seed is caught, `… status` prints the worklist, `… pg-surface` regenerates the listing from a container, `… clones` prints the sibling divergences with their waiver status - `tools/oracles.cs` — The local prover and status report for `test/oracles/`; file-based app, never run in CI -- `test/consumer-smoke-test.sh` — The only check of *delivery* rather than code: packs the four packages, restores them into throwaway projects created outside the repository (inside it, `Directory.Build.props` would apply), compiles and runs real code against them, and asserts on printed output and translated SQL — never on the exit code alone. Four consumers: core only; a Native AOT publish of core + NodaTime, run as a native binary (extra linker paths via `SMOKE_AOT_LINKER_ARGS`, e.g. for Homebrew's dotnet); the NodaTime EF satellite, which pulls in all four through the nuspec chain; and the EF package beside `EFCore.ComplexIndexes.PostgreSQL` from nuget.org, asserting its exclusion and temporal constraints over this package's columns in the create script. `NUGET_PACKAGES` is redirected to a private folder because NuGet resolves id+version from the global cache before any source, so a locally built package is otherwise shadowed by whatever build of that version was restored before; the generated `nuget.config` uses package source mapping so this repo's ids come from the local feed only and everything else from nuget.org. Runs on every PR in both modes (own feed; the pre-built `dist` the release workflow passes). Everything is discovered (projects by globbing `src/`, types by reflection), so adding a package or a type needs no edit here +- `test/consumer-smoke-test.sh` — The only check of *delivery* rather than code: packs the four packages, restores them into throwaway projects created outside the repository (inside it, `Directory.Build.props` would apply), compiles and runs real code against them, and asserts on printed output and translated SQL — never on the exit code alone. Four consumers: core only; a Native AOT publish of core + NodaTime, run as a native binary (extra linker paths via `SMOKE_AOT_LINKER_ARGS`, e.g. for Homebrew's dotnet); the NodaTime EF satellite, which pulls in all four through the nuspec chain; and the EF package beside `EFCore.ComplexIndexes.PostgreSQL` from nuget.org, asserting its exclusion and temporal constraints over this package's columns in the create script (skipped on the 11 line until CaffeinatedCoder/EFCore.ComplexIndexes#38, like `ComplexIndexesCrossTests`). `NUGET_PACKAGES` is redirected to a private folder because NuGet resolves id+version from the global cache before any source, so a locally built package is otherwise shadowed by whatever build of that version was restored before; the generated `nuget.config` uses package source mapping so this repo's ids come from the local feed only and everything else from nuget.org. Runs on every PR in both modes (own feed; the pre-built `dist` the release workflow passes). Everything is discovered (projects by globbing `src/`, types by reflection), so adding a package or a type needs no edit here - `docs/` — Agent docs (read relevant doc before starting work) ## Commands diff --git a/CHANGELOG.md b/CHANGELOG.md index 06dae170..a4d7dcfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,23 @@ A version's section is the GitHub release's notes. Each line is one change: what to do about it, and a link to the guide with the detail. [CONTRIBUTING.md](CONTRIBUTING.md#changelog) has the rules. +## [11.0.0-preview.1] — 2026-10-19 + +The first preview of the 11 line: the same public API as 10.0.0, on .NET 11. Nothing was removed or renamed. The 10.x line stays on .NET 10 ([Branches and releases](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/CONTRIBUTING.md#branches-and-releases)). + +### Breaking + +- All four packages target `net11.0` and need the .NET 11 runtime, one target framework per line; the EF Core packages reference EF Core 11 and `Npgsql.EntityFrameworkCore.PostgreSQL` 11 (release candidates while .NET 11 is in preview). PostgreSQL 16 or later, as in 10.x. + +### Changed + +- EF Core: an `ExecuteUpdate` that sets a nullable value set inside a JSON column to a value that may be null is refused for the JSON array alone; Npgsql 11 writes the null outcome as JSON null, so the message no longer names a whole-document NULL ([JSON columns](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#put-a-range-or-set-inside-a-json-column)). +- EF Core: an empty captured list of ranges or sets reads no rows through EF Core 11's own `SELECT … WHERE FALSE`; the SQL differs from 10.x, the answers do not ([Captured lists](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#match-a-column-against-a-list-of-sets)). + +### Fixed + +- Value sets: every set type implements `IFormattable` itself, so `ToString()` and formatting no longer run the interface's default, whose shared-generic stub traps under Native AOT with ILCompiler 11 RC2 ([Native AOT](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#native-aot)). + ## [10.0.0] — 2026-10-19 Nothing was removed or renamed. Some calls answer differently, and text PostgreSQL refuses is refused here too: [Migration from v9.x](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/migration.md#migration-from-v9x). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1cf5da14..8cd56916 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ dotnet build CodoMetis.ValueRanges.slnx dotnet test ``` -`global.json` pins the SDK to the line's major (10.0.x on `main`), so install a .NET 10 SDK; a +`global.json` pins the SDK to the line's major (11.0.x on `main`, 10.0.x on `release/10.x`), so install a .NET 11 SDK; a newer major on the machine is refused rather than silently used ([branches and releases](#branches-and-releases)). @@ -177,7 +177,10 @@ fails outright. on, a minor on one line moves its row and `CompanionLineRelease` on the other branch in a PR of its own. The table gets its second row in the PR that opens the first version after `v11.0.0`. - **The ApiCompat baseline** is the latest stable release before the version being prepared, - never a preview: the 11 line validates against 10.0.0 until 11.0.0 ships. + never a preview: the 11 line validates against 10.0.0 until 11.0.0 ships. Package validation + cannot pair a `net11.0` asset with a `net10.0` baseline, so until then `Directory.Build.props` + ignores the baseline's framework and each preview's PR quotes a `dotnet apicompat` run over the + two assemblies instead; the mechanical gate returns when 11.0.0 is the baseline. - **GitHub's Latest release** is the highest stable version. The release workflow decides it rather than trusting the API's default, so a 10.x tag pushed after 11.0.0 exists, or any preview, can't take Latest from it. diff --git a/Directory.Build.props b/Directory.Build.props index 8f0ce31b..07be7724 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 10.0.0 + 11.0.0-preview.1 CaffeinatedCoder MIT true @@ -64,9 +64,24 @@ --> true - 9.1.0 + 10.0.0 + + + + + true - net10.0 + net11.0 enable enable true - net10.0 + net11.0 enable enable CodoMetis.ValueRanges README.md true - In-memory range and multirange types for .NET 10, mirroring PostgreSQL's six built-in range domains (int4range, int8range, numrange, daterange, tsrange, tstzrange) plus TimeRange over TimeOnly — the time-of-day range PostgreSQL users conventionally add as CREATE TYPE timerange AS RANGE (subtype = time), and Float64Range and Float32Range over finite double and float (the custom float8range and float4range). Each type is a discriminated union of five sealed variants (Finite, UnboundedStart, UnboundedEnd, EmptyRange, Infinity) with invalid states unrepresentable at compile time. + In-memory range and multirange types for .NET 11, mirroring PostgreSQL's six built-in range domains (int4range, int8range, numrange, daterange, tsrange, tstzrange) plus TimeRange over TimeOnly — the time-of-day range PostgreSQL users conventionally add as CREATE TYPE timerange AS RANGE (subtype = time), and Float64Range and Float32Range over finite double and float (the custom float8range and float4range). Each type is a discriminated union of five sealed variants (Finite, UnboundedStart, UnboundedEnd, EmptyRange, Infinity) with invalid states unrepresentable at compile time. Includes the full PostgreSQL interval algebra — Contains, Overlaps, IsAdjacentTo, Intersect, Union, Except, Complement, Merge (range_merge), bound accessors (lower/upper/lower_inc/upper_inc), the RangeAgg/RangeIntersectAgg aggregates, Gap/Gaps, Shift/Expand, Split, the Month/Quarter/Year/IsoWeek calendar factories and IComparable in PostgreSQL's range order — plus RangeSet<TRange, T> as an immutable, always-normalized multirange with the complete multirange operator matrix. diff --git a/src/CodoMetis.ValueRanges/Internals/IsoTemporal.cs b/src/CodoMetis.ValueRanges/Internals/IsoTemporal.cs index 6c881cae..9aceb6be 100644 --- a/src/CodoMetis.ValueRanges/Internals/IsoTemporal.cs +++ b/src/CodoMetis.ValueRanges/Internals/IsoTemporal.cs @@ -60,10 +60,30 @@ internal static DateOnly ParseDate(ReadOnlySpan s) } internal static TimeOnly ParseTime(ReadOnlySpan s) - => TimeOnly.TryParseExact(TruncateFraction(s), TimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var value) + => !StartsWithHour24(s, 0) + && TimeOnly.TryParseExact(TruncateFraction(s), TimeFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var value) ? value : throw new FormatException("Expected an ISO 8601 time of day, HH:mm or HH:mm:ss with up to seven fraction digits."); + /// + /// Whether the time of day starting at has the hour 24. + /// + /// + /// ISO 8601's end-of-day form. .NET 11 reads it: 24:00:00 as 00:00:00 for a + /// , and 2026-01-01T24:00:00 as the next day's midnight for a + /// or , where .NET 10 refused both. The grammar + /// refuses it on every platform: a time of 24:00:00 is a PostgreSQL value + /// cannot hold, so reading it as midnight would store a different value, and + /// a timestamp is never printed that way by PostgreSQL or this library, so accepting it on one + /// line would give a literal a meaning the other line refuses. Checked before the BCL parse, since + /// afterwards the next day's midnight is indistinguishable from the literal that names it (#286). + /// + private static bool StartsWithHour24(ReadOnlySpan s, int timeStart) + => s.Length >= timeStart + 3 && s[timeStart] == '2' && s[timeStart + 1] == '4' && s[timeStart + 2] == ':'; + + /// The position of the time of day in a date-and-time literal, after yyyy-MM-dd and its separator. + private const int TimeStartInDateTime = 11; + /// /// The offset is not applied. A DateTime range is a tsrange, which stores a wall /// clock and no zone, and PostgreSQL's own timestamp input keeps the wall clock and drops @@ -90,7 +110,8 @@ internal static DateTime ParseDateTime(ReadOnlySpan s) text = text[..^length]; } - return DateTime.TryParseExact(text, WallClockFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var value) + return !StartsWithHour24(text, TimeStartInDateTime) + && DateTime.TryParseExact(text, WallClockFormats, CultureInfo.InvariantCulture, DateTimeStyles.None, out var value) ? DateTime.SpecifyKind(value, kind) : throw new FormatException( "Expected an ISO 8601 date and time, yyyy-MM-dd then T or a space then HH:mm[:ss[.fffffff]], " @@ -139,7 +160,7 @@ internal static DateTimeOffset ParseDateTimeOffset(ReadOnlySpan s) // The offset is Z, ±HH, ±HH:mm or ±HH:mm:ss, as for a DateTime; .NET's zzz would also read // +0530 and +5:30, which the grammar and the sibling types refuse (#234). - if (!trimmed.EndsWith('Z') && OffsetLength(trimmed) == 0) throw InvalidDateTimeOffset(); + if (StartsWithHour24(trimmed, TimeStartInDateTime) || !trimmed.EndsWith('Z') && OffsetLength(trimmed) == 0) throw InvalidDateTimeOffset(); return DateTimeOffset.TryParseExact(trimmed, DateTimeOffsetFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var value) || TryParseWideOffset(trimmed, out value) diff --git a/src/CodoMetis.ValueRanges/README.md b/src/CodoMetis.ValueRanges/README.md index 30839288..2dfe306e 100644 --- a/src/CodoMetis.ValueRanges/README.md +++ b/src/CodoMetis.ValueRanges/README.md @@ -1,6 +1,6 @@ # CodoMetis.ValueRanges -Range types and value sets for .NET 10 that work entirely in memory. You get PostgreSQL's complete +Range types and value sets for .NET 11 that work entirely in memory. You get PostgreSQL's complete range and set algebra, with no database dependency. You get two families of types. Both are immutable, and both are in canonical form from the moment @@ -21,7 +21,7 @@ memory and in a query. dotnet add package CodoMetis.ValueRanges ``` -> Requires .NET 10 or later. +> Requires .NET 11 or later; the 10.x line stays on .NET 10. **Native AOT and trimming compatible.** Your publish gets no trim or AOT warnings, and a NativeAOT consumer in CI verifies this. For JSON under Native AOT you need a source-generated context diff --git a/src/CodoMetis.ValueRanges/Sets/DateSet.cs b/src/CodoMetis.ValueRanges/Sets/DateSet.cs index 36a4e120..04b37a18 100644 --- a/src/CodoMetis.ValueRanges/Sets/DateSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/DateSet.cs @@ -120,7 +120,12 @@ public bool Equals(DateSet? other) public static bool operator !=(DateSet? left, DateSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -280,5 +285,10 @@ public bool Equals(DateSet? other) public static bool operator !=(DateSet? left, DateSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/DateTimeOffsetSet.cs b/src/CodoMetis.ValueRanges/Sets/DateTimeOffsetSet.cs index 67d7d1e0..00f119b6 100644 --- a/src/CodoMetis.ValueRanges/Sets/DateTimeOffsetSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/DateTimeOffsetSet.cs @@ -123,7 +123,12 @@ public bool Equals(DateTimeOffsetSet? other) public static bool operator !=(DateTimeOffsetSet? left, DateTimeOffsetSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -284,5 +289,10 @@ public bool Equals(DateTimeOffsetSet? other) public static bool operator !=(DateTimeOffsetSet? left, DateTimeOffsetSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/DateTimeSet.cs b/src/CodoMetis.ValueRanges/Sets/DateTimeSet.cs index 91c8cb62..b96d93f3 100644 --- a/src/CodoMetis.ValueRanges/Sets/DateTimeSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/DateTimeSet.cs @@ -123,7 +123,12 @@ public bool Equals(DateTimeSet? other) public static bool operator !=(DateTimeSet? left, DateTimeSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -285,5 +290,10 @@ public bool Equals(DateTimeSet? other) public static bool operator !=(DateTimeSet? left, DateTimeSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/DecimalSet.cs b/src/CodoMetis.ValueRanges/Sets/DecimalSet.cs index 5b06b9be..4da6eef6 100644 --- a/src/CodoMetis.ValueRanges/Sets/DecimalSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/DecimalSet.cs @@ -119,7 +119,12 @@ public bool Equals(DecimalSet? other) public static bool operator !=(DecimalSet? left, DecimalSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -284,5 +289,10 @@ public bool Equals(DecimalSet? other) public static bool operator !=(DecimalSet? left, DecimalSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/Float32Set.cs b/src/CodoMetis.ValueRanges/Sets/Float32Set.cs index 00855516..14c6c641 100644 --- a/src/CodoMetis.ValueRanges/Sets/Float32Set.cs +++ b/src/CodoMetis.ValueRanges/Sets/Float32Set.cs @@ -143,7 +143,12 @@ public bool Equals(Float32Set? other) public static bool operator !=(Float32Set? left, Float32Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -333,5 +338,10 @@ public bool Equals(Float32Set? other) public static bool operator !=(Float32Set? left, Float32Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/Float64Set.cs b/src/CodoMetis.ValueRanges/Sets/Float64Set.cs index 5d635e2e..2446e1a0 100644 --- a/src/CodoMetis.ValueRanges/Sets/Float64Set.cs +++ b/src/CodoMetis.ValueRanges/Sets/Float64Set.cs @@ -143,7 +143,12 @@ public bool Equals(Float64Set? other) public static bool operator !=(Float64Set? left, Float64Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -333,5 +338,10 @@ public bool Equals(Float64Set? other) public static bool operator !=(Float64Set? left, Float64Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/GuidSet.cs b/src/CodoMetis.ValueRanges/Sets/GuidSet.cs index 0b5662ec..e598015a 100644 --- a/src/CodoMetis.ValueRanges/Sets/GuidSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/GuidSet.cs @@ -118,7 +118,12 @@ public bool Equals(GuidSet? other) public static bool operator !=(GuidSet? left, GuidSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -276,5 +281,10 @@ public bool Equals(GuidSet? other) public static bool operator !=(GuidSet? left, GuidSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/Int16Set.cs b/src/CodoMetis.ValueRanges/Sets/Int16Set.cs index c457d2e7..e2fd28a5 100644 --- a/src/CodoMetis.ValueRanges/Sets/Int16Set.cs +++ b/src/CodoMetis.ValueRanges/Sets/Int16Set.cs @@ -116,7 +116,12 @@ public bool Equals(Int16Set? other) public static bool operator !=(Int16Set? left, Int16Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -280,5 +285,10 @@ public bool Equals(Int16Set? other) public static bool operator !=(Int16Set? left, Int16Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/Int32Set.cs b/src/CodoMetis.ValueRanges/Sets/Int32Set.cs index 5ce4916b..fc71f7c1 100644 --- a/src/CodoMetis.ValueRanges/Sets/Int32Set.cs +++ b/src/CodoMetis.ValueRanges/Sets/Int32Set.cs @@ -116,7 +116,12 @@ public bool Equals(Int32Set? other) public static bool operator !=(Int32Set? left, Int32Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -273,5 +278,10 @@ public bool Equals(Int32Set? other) public static bool operator !=(Int32Set? left, Int32Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/Int64Set.cs b/src/CodoMetis.ValueRanges/Sets/Int64Set.cs index 306400c3..7e8daf63 100644 --- a/src/CodoMetis.ValueRanges/Sets/Int64Set.cs +++ b/src/CodoMetis.ValueRanges/Sets/Int64Set.cs @@ -116,7 +116,12 @@ public bool Equals(Int64Set? other) public static bool operator !=(Int64Set? left, Int64Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -273,5 +278,10 @@ public bool Equals(Int64Set? other) public static bool operator !=(Int64Set? left, Int64Set? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/StringSet.cs b/src/CodoMetis.ValueRanges/Sets/StringSet.cs index a8723be1..3ad34939 100644 --- a/src/CodoMetis.ValueRanges/Sets/StringSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/StringSet.cs @@ -139,7 +139,12 @@ public bool Equals(StringSet? other) public static bool operator !=(StringSet? left, StringSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -333,5 +338,10 @@ public bool Equals(StringSet? other) public static bool operator !=(StringSet? left, StringSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/src/CodoMetis.ValueRanges/Sets/TimeSet.cs b/src/CodoMetis.ValueRanges/Sets/TimeSet.cs index 04247d4f..2ee96606 100644 --- a/src/CodoMetis.ValueRanges/Sets/TimeSet.cs +++ b/src/CodoMetis.ValueRanges/Sets/TimeSet.cs @@ -122,7 +122,12 @@ public bool Equals(TimeSet? other) public static bool operator !=(TimeSet? left, TimeSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format(this, format, provider); } /// @@ -281,5 +286,10 @@ public bool Equals(TimeSet? other) public static bool operator !=(TimeSet? left, TimeSet? right) => !(left == right); /// - public override string ToString() => ((IFormattable)this).ToString(null, CultureInfo.InvariantCulture); + public override string ToString() => SetFormat.Format, TElement>(this, null, CultureInfo.InvariantCulture); + + // Implemented here rather than left to the interface's default: ILCompiler 11 RC2 compiles the + // default's shared-generic stub to a trap under Native AOT (#291). + string IFormattable.ToString(string? format, IFormatProvider? provider) + => SetFormat.Format, TElement>(this, format, provider); } diff --git a/test/CodoMetis.ValueRanges.AspNetCore.Tests/CodoMetis.ValueRanges.AspNetCore.Tests.csproj b/test/CodoMetis.ValueRanges.AspNetCore.Tests/CodoMetis.ValueRanges.AspNetCore.Tests.csproj index f85f88af..08fbc3e1 100644 --- a/test/CodoMetis.ValueRanges.AspNetCore.Tests/CodoMetis.ValueRanges.AspNetCore.Tests.csproj +++ b/test/CodoMetis.ValueRanges.AspNetCore.Tests/CodoMetis.ValueRanges.AspNetCore.Tests.csproj @@ -1,7 +1,7 @@ - net10.0 + net11.0 enable enable false @@ -13,8 +13,8 @@ - - + + diff --git a/test/CodoMetis.ValueRanges.Conventions.Tests/CodoMetis.ValueRanges.Conventions.Tests.csproj b/test/CodoMetis.ValueRanges.Conventions.Tests/CodoMetis.ValueRanges.Conventions.Tests.csproj index b5e50870..afa33a76 100644 --- a/test/CodoMetis.ValueRanges.Conventions.Tests/CodoMetis.ValueRanges.Conventions.Tests.csproj +++ b/test/CodoMetis.ValueRanges.Conventions.Tests/CodoMetis.ValueRanges.Conventions.Tests.csproj @@ -1,7 +1,7 @@ - net10.0 + net11.0 enable enable false @@ -11,8 +11,8 @@ - - + + diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests.csproj b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests.csproj index e285c1b9..d02d4254 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests.csproj +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.InfinityDisabled.IntegrationTests.csproj @@ -1,7 +1,7 @@ - net10.0 + net11.0 enable enable false diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests.csproj b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests.csproj index bcb39047..be90ff9c 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests.csproj +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests.csproj @@ -1,7 +1,7 @@ - net10.0 + net11.0 enable enable false @@ -15,20 +15,31 @@ Test-only, and only here: ComplexIndexesCrossTests proves that this package's columns work under EFCore.ComplexIndexes.PostgreSQL's temporal and exclusion constraints and GiST indexes. Neither shipping package references the other. + + Off on the 11 line until ComplexIndexes ships its own 11.0.0-preview.1 + (CaffeinatedCoder/EFCore.ComplexIndexes#38): 5.4.x pins Npgsql.EntityFrameworkCore.PostgreSQL + to [10.0.0, 11.0.0), which a net11.0 restore cannot satisfy. The condition keeps the reference + and the test file where they are, so CaffeinatedCoder/EFCore.ComplexIndexes#42 restores them + by moving the version and dropping the condition (#103). --> - + - + + + + + + - + diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/EfCore11ShapeTests.cs b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/EfCore11ShapeTests.cs new file mode 100644 index 00000000..7b670cea --- /dev/null +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/EfCore11ShapeTests.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore; + +namespace CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests; + +/// +/// Two shapes EF Core 11 gives a query before the plugin sees it, held here without a database so a +/// revert of either fix fails on ToQueryString alone. EfCore11RetargetTests (integration) +/// runs the same against a live server. +/// +[TestClass] +public sealed class EfCore11ShapeTests +{ + private static readonly DateOnly Day = new(2024, 6, 15); + + private static string Sql(Func> query) + { + using var db = new TestDbContext(); + return query(db).ToQueryString(); + } + + /// + /// EF Core 11 rewrites every Contains on an into + /// Queryable.Contains over the element type, which for a is + /// the range; the operand of Contains(T) and Contains(RangeSet) is not one, and the + /// rewrite threw inside EF Core (#287). The interceptor hands the + /// three overloads over as static calls, which translate to @> as before. + /// + [TestMethod] + public void RangeSetContains_EveryOverload_TranslatesToContainment_NotEfCoresCollectionContains() + { + var other = RangeSet.From([DateRange.CreateFinite(Day, Day.AddDays(2))]); + + StringAssert.Contains(Sql(db => db.Bookings.Where(b => b.BlockedDays.Contains(Day))), "b.\"BlockedDays\" @> DATE '2024-06-15'"); + StringAssert.Contains(Sql(db => db.Bookings.Where(b => b.BlockedDays.Contains(b.Period))), "b.\"BlockedDays\" @> b.\"Period\""); + StringAssert.Contains(Sql(db => db.Bookings.Where(b => b.BlockedDays.Contains(other))), "b.\"BlockedDays\" @> @other"); + StringAssert.Contains(Sql(db => db.Bookings.Where(b => other.Contains(b.Period))), "@other @> b.\"Period\""); + } + + /// + /// EF Core 11 writes a == b ? null : a as NULLIF(a, b). Over a server-side + /// Union that is array equality over a concatenation, refused as equality — the guard's + /// CASE arm no longer sees it, so NULLIF has an arm of its own (#103). + /// + [TestMethod] + public void NullIf_OverAServerSideUnion_IsRefusedAsEquality() + { + var operand = StringSet.From("a", "b"); + var target = StringSet.From("a", "b", "c"); + + using var db = new TestDbContext(); + StringAssert.Contains(db.Bookings.Select(b => b.Id == 5 ? (int?)null : b.Id).ToQueryString(), "NULLIF("); + + var refusal = Assert.ThrowsExactly( + () => db.Bookings.Select(b => b.Tags.Union(operand) == target ? null : b.Tags.Union(operand)).ToQueryString()); + + StringAssert.Contains(refusal.Message, "Value set equality"); + } +} diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ExecuteUpdateGuardTests.cs b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ExecuteUpdateGuardTests.cs index 6ce57377..2db77d3a 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ExecuteUpdateGuardTests.cs +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ExecuteUpdateGuardTests.cs @@ -77,9 +77,14 @@ public void AValueSetInANestedComplexTypeOfAJsonColumn_IsRefused() } // -- Null gets its own message (#57); what PostgreSQL does with each is measured in ExecuteUpdateJsonTests -- + // + // Until 10.0.0 a value that may be null on some row was refused for a second reason, "writes NULL as + // the whole document": jsonb_set returned NULL for a NULL value. Npgsql 11 writes such a value through + // jsonb_set_lax, or coalesces it to JSON null, so the null outcome is right and only the JSON array is + // refused (#289). private const string ArrayReason = "stores a JSON array"; - private const string NullReason = "writes NULL as the whole document"; + private const string NullReason = "cannot type the untyped NULL (42804)"; [TestMethod] public void ANullConstant_IsRefusedForWhatNullDoes() @@ -93,7 +98,7 @@ public void ANullParameter_IsRefusedForWhatNullDoes() } [TestMethod] - public void AConditionalWithANullBranch_IsRefusedForBothOutcomes() + public void AConditionalWithANullBranch_IsRefusedForTheJsonArrayOnly() { var some = StringSet.From("a"); AssertMaybeNullRefusal(() => new UpdateTestContext().Rows.ExecuteUpdate( @@ -101,7 +106,7 @@ public void AConditionalWithANullBranch_IsRefusedForBothOutcomes() } [TestMethod] - public void ANullableColumn_IsRefusedForBothOutcomes() + public void ANullableColumn_IsRefusedForTheJsonArrayOnly() => AssertMaybeNullRefusal(() => new UpdateTestContext().Rows.ExecuteUpdate( s => s.SetProperty(r => r.Doc.MaybeTags, r => r.MaybeCodes))); @@ -133,6 +138,6 @@ private static void AssertMaybeNullRefusal(Action update) StringAssert.Contains(refusal.Message, "'Doc.MaybeTags' inside a JSON column."); StringAssert.Contains(refusal.Message, ArrayReason); - StringAssert.Contains(refusal.Message, NullReason); + Assert.IsFalse(refusal.Message.Contains(NullReason), refusal.Message); } } diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/RangeCollectionTranslationTests.cs b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/RangeCollectionTranslationTests.cs index 13fcbf25..3c9f3e3e 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/RangeCollectionTranslationTests.cs +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/RangeCollectionTranslationTests.cs @@ -91,7 +91,7 @@ public void AnyAlone_OverAnEmptyCapturedList_ReadsNoRows() var wanted = new List(); Assert.AreEqual( - "WHERE EXISTS ( SELECT 1 FROM (VALUES (NULL::int4range)) AS w(\"Value\") WHERE FALSE)", + "WHERE EXISTS ( SELECT 1 FROM ( SELECT NULL::int4range AS \"Value\" WHERE FALSE ) AS w WHERE w.\"Value\" && b.\"Seats\")", Where(db => db.Bookings.Where(b => wanted.Any(w => w.Overlaps(b.Seats))))); } @@ -108,9 +108,10 @@ public void Any_OverACapturedListAContainsAlsoReads_ReadsTheRangesFromValues() /// /// An empty captured collection sent one parameter per range expands to a VALUES with no - /// rows, which EF Core's SQL generator refuses (#137). It reads no rows instead: one row of typed - /// NULLs under FALSE, with the predicate folded away under it. Contains over it - /// is EF Core's own FALSE, folded out of the OR. + /// rows (#137). EF Core 11 reads no rows for it itself — a table-less SELECT of NULLs + /// under WHERE FALSE — and the plugin casts each NULL to the column's type, since a + /// bare one is text to PostgreSQL and fails the operator on it (#290). Contains over + /// it is EF Core's own FALSE, folded out of the OR. /// [TestMethod] public void AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows() @@ -118,7 +119,7 @@ public void AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows() var wanted = new List(); Assert.AreEqual( - "WHERE EXISTS ( SELECT 1 FROM (VALUES (NULL::int4range)) AS w(\"Value\") WHERE FALSE)", + "WHERE EXISTS ( SELECT 1 FROM ( SELECT NULL::int4range AS \"Value\" WHERE FALSE ) AS w WHERE w.\"Value\" && b.\"Seats\")", Where(db => db.Bookings.Where(b => wanted.Contains(b.Seats) || wanted.Any(w => w.Overlaps(b.Seats))))); } diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SetCollectionTranslationTests.cs b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SetCollectionTranslationTests.cs index edf194d4..961528c1 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SetCollectionTranslationTests.cs +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SetCollectionTranslationTests.cs @@ -74,11 +74,11 @@ public void Any_OverACapturedList_ReadsTheSetsFromValues() } /// - /// An empty captured collection expands to a VALUES with no rows, which EF Core's SQL - /// generator refuses ("Empty collections are not supported as inline query roots", #137). It is - /// given one row of typed NULLs and FALSE on its WHERE instead — EF Core folds - /// the predicate away under it — so the subquery reads no rows and Any is - /// , Count is 0. + /// An empty captured collection expands to a VALUES with no rows (#137). EF Core 11 reads + /// no rows for it itself — a table-less SELECT of NULLs under WHERE FALSE — and + /// the plugin casts each NULL to the column's type, since a bare one is text to + /// PostgreSQL and fails the operator on it (#290); so Any is and + /// Count is 0. /// [TestMethod] public void Any_OverAnEmptyCapturedList_ReadsNoRows() @@ -86,7 +86,7 @@ public void Any_OverAnEmptyCapturedList_ReadsNoRows() var wanted = new List(); Assert.AreEqual( - "WHERE EXISTS ( SELECT 1 FROM (VALUES (NULL::text[])) AS w(\"Value\") WHERE FALSE)", + "WHERE EXISTS ( SELECT 1 FROM ( SELECT NULL::text[] AS \"Value\" WHERE FALSE ) AS w WHERE w.\"Value\" && b.\"Tags\")", Where(db => db.Bookings.Where(b => wanted.Any(w => w.Overlaps(b.Tags))))); } @@ -97,7 +97,7 @@ public void Count_OverAnEmptyCapturedList_ReadsNoRows() StringAssert.Contains( Where(db => db.Bookings.Where(b => wanted.Count(w => w.IsSubsetOf(b.Tags)) == 0)), - "WHERE ( SELECT count(*)::int FROM (VALUES (NULL::text[])) AS w(\"Value\") WHERE FALSE) = 0"); + "WHERE ( SELECT count(*)::int FROM ( SELECT NULL::text[] AS \"Value\" WHERE FALSE ) AS w WHERE w.\"Value\" <@ b.\"Tags\") = 0"); } [TestMethod] diff --git a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SqlProcessingCostTests.cs b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SqlProcessingCostTests.cs index 9f871e99..af297c3f 100644 --- a/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SqlProcessingCostTests.cs +++ b/test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/SqlProcessingCostTests.cs @@ -4,7 +4,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Query; -using Microsoft.EntityFrameworkCore.Storage; namespace CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests; @@ -28,14 +27,13 @@ public void EmptyCollectionRewriter_VisitsEachNodeOnce() { using var context = new TestDbContext(); var factory = context.GetService(); - var mappings = context.GetService(); const int depth = 12; var counter = new VisitCounter(); Expression tree = Expression.Constant(0); for (var level = 0; level < depth; level++) tree = new CountingNode(tree, counter); - EmptyCollectionRewriter.Rewrite(tree, factory, mappings); + EmptyCollectionRewriter.Rewrite(tree, factory); Assert.AreEqual(depth, counter.Visits, $"A chain of {depth} nodes was visited {counter.Visits} times."); } diff --git a/test/CodoMetis.ValueRanges.NodaTime.Tests/CodoMetis.ValueRanges.NodaTime.Tests.csproj b/test/CodoMetis.ValueRanges.NodaTime.Tests/CodoMetis.ValueRanges.NodaTime.Tests.csproj index f5058489..d9a178d5 100644 --- a/test/CodoMetis.ValueRanges.NodaTime.Tests/CodoMetis.ValueRanges.NodaTime.Tests.csproj +++ b/test/CodoMetis.ValueRanges.NodaTime.Tests/CodoMetis.ValueRanges.NodaTime.Tests.csproj @@ -1,7 +1,7 @@  - net10.0 + net11.0 enable enable false diff --git a/test/CodoMetis.ValueRanges.Tests/CodoMetis.ValueRanges.Tests.csproj b/test/CodoMetis.ValueRanges.Tests/CodoMetis.ValueRanges.Tests.csproj index 72977cf9..4dc71a0d 100644 --- a/test/CodoMetis.ValueRanges.Tests/CodoMetis.ValueRanges.Tests.csproj +++ b/test/CodoMetis.ValueRanges.Tests/CodoMetis.ValueRanges.Tests.csproj @@ -1,7 +1,7 @@  - net10.0 + net11.0 enable enable false diff --git a/test/CodoMetis.ValueRanges.Tests/TemporalLiteralGrammarTests.cs b/test/CodoMetis.ValueRanges.Tests/TemporalLiteralGrammarTests.cs index 15177af7..ce7765d5 100644 --- a/test/CodoMetis.ValueRanges.Tests/TemporalLiteralGrammarTests.cs +++ b/test/CodoMetis.ValueRanges.Tests/TemporalLiteralGrammarTests.cs @@ -150,6 +150,8 @@ public void DateTime_Accepts_Infinity() [DataRow("2027-02-01T09")] [DataRow("2027-02-01T09:30:00,5")] // comma fraction [DataRow("2027-02-01T25:00:00")] + [DataRow("2027-02-01T24:00:00")] // ISO 8601's end of day, which .NET 11 reads as the + [DataRow("2027-02-01 24:00")] // next day's midnight; PostgreSQL never prints it [DataRow("2027-02-01T09:30:00 BC")] [DataRow("2027-02-01T09:30:00+0530")] // offsets are ±HH, ±HH:mm or ±HH:mm:ss [DataRow("2027-02-01T09:30:00+5:30")] @@ -239,6 +241,8 @@ public void DateTimeOffset_Accepts_Infinity() [DataRow("2026-01-01T09:30:00+16:00:00")] // PostgreSQL stops at ±15:59:59 [DataRow("2026-01-01T09:30:00+16:00")] [DataRow("2026-01-01 09:30:00-16")] + [DataRow("2026-01-01T24:00:00Z")] // ISO 8601's end of day: .NET 11 would read the next day + [DataRow("2026-01-01 24:00:00+05:30:00")] [DataRow("2026-01-01T09:30:00+15:60")] [DataRow("2026-01-01T09:30:00+05:30:60")] [DataRow("2026-01-01T09:30:00x05:30:00")] // a seconds offset needs its sign @@ -283,7 +287,9 @@ public void Time_Accepts(string text, long extraTicks) [TestMethod] [DataRow("9:30 AM")] [DataRow("9:30")] - [DataRow("24:00:00")] // PostgreSQL's end of day: unrepresentable + [DataRow("24:00:00")] // PostgreSQL's end of day: unrepresentable, and + [DataRow("24:00")] // .NET 11 would read it as 00:00 + [DataRow("24:00:00.0")] [DataRow("09.30")] [DataRow("09:30:00,5")] [DataRow("T09:30")] diff --git a/test/consumer-smoke-test.sh b/test/consumer-smoke-test.sh index 8ef1b81f..e9fee7f3 100755 --- a/test/consumer-smoke-test.sh +++ b/test/consumer-smoke-test.sh @@ -50,6 +50,9 @@ export NUGET_PACKAGES="$work/packages" version="$(dotnet msbuild "$repo_root/src/CodoMetis.ValueRanges/CodoMetis.ValueRanges.csproj" -getProperty:Version)" version="$(echo "$version" | tr -d '[:space:]')" +# The consumers target what the packages target, so the 10.x and 11.x lines run the same script. +tfm="$(dotnet msbuild "$repo_root/src/CodoMetis.ValueRanges/CodoMetis.ValueRanges.csproj" -getProperty:TargetFramework)" +tfm="$(echo "$tfm" | tr -d '[:space:]')" if [[ -z "$feed" ]]; then feed="$work/feed" @@ -102,7 +105,7 @@ scaffold_consumer() { echo "==> $name: consumer project, $package" mkdir -p "$app" cd "$app" - run dotnet new console --framework net10.0 --output . + run dotnet new console --framework "$tfm" --output . cat > nuget.config < @@ -556,8 +559,21 @@ assert_contains '"Tags" @> ARRAY['"'"'x'"'"']::text[]' "$work/postgres.out" "va # packages restore and compose in one consumer, from the feeds a consumer uses. GenerateCreateScript # runs the other package's differ (registered by UseNpgsqlComplexIndexes()), which renders the same # statements a migration would, and needs no database. +# +# Only on the 10 line until EFCore.ComplexIndexes.PostgreSQL ships its own 11.0.0-preview.1 +# (CaffeinatedCoder/EFCore.ComplexIndexes#38): 5.4.x pins Npgsql.EntityFrameworkCore.PostgreSQL to +# [10.0.0, 11.0.0), which a net11.0 consumer cannot restore. CaffeinatedCoder/EFCore.ComplexIndexes#42 +# moves the version and drops the condition (#103). complex_indexes_version=5.4.0 +if [[ "$tfm" != "net10.0" ]]; then + echo "==> complexindexes: skipped on $tfm until EFCore.ComplexIndexes.PostgreSQL supports it (CaffeinatedCoder/EFCore.ComplexIndexes#38)" + [[ $failed -eq 0 ]] || { echo; echo "consumer smoke test FAILED"; exit 1; } + echo + echo "consumer smoke test passed ($version)" + exit 0 +fi + cat > "$work/complexindexes.cs" <<'CSHARP' using CodoMetis.ValueRanges; using EFCore.ComplexIndexes.PostgreSQL; diff --git a/test/oracles/claims.json b/test/oracles/claims.json index 2936793b..4ed5d975 100644 --- a/test/oracles/claims.json +++ b/test/oracles/claims.json @@ -514,8 +514,8 @@ { "id": "E27-executeupdate-null-fails", "source": "docs/efcore.md#put-a-range-or-set-inside-a-json-column", - "quote": "fails for every type — a range or multirange in Npgsql (`42804`); a value set is refused before it reaches Npgsql, because a `NULL` written there would turn the whole document into `NULL`. Set it to `null` with `SaveChanges`, or replace the whole JSON property", - "claim": "ExecuteUpdate setting a range, temporal range or multirange property inside a JSON document to null fails with PostgreSQL error 42804; a value set property set to null (constant or parameter) is refused by the plugin with InvalidOperationException before reaching Npgsql, with a message of its own naming the whole-document NULL rather than the JSON array, and one that may be null names both; the row still loads afterwards, and SaveChanges or replacing the whole JSON property writes the null.", + "quote": "fails for every type — a range or multirange in Npgsql (`42804`, the untyped `NULL` in `to_jsonb(NULL)`); a value set is refused before it reaches Npgsql, for the same reason. Set it to `null` with `SaveChanges`, or replace the whole JSON property", + "claim": "ExecuteUpdate setting a range, temporal range or multirange property inside a JSON document to null fails with PostgreSQL error 42804; a value set property set to null (constant or parameter) is refused by the plugin with InvalidOperationException before reaching Npgsql, with a message of its own naming the untyped NULL rather than the JSON array, and one that may be null is refused for the JSON array; the row still loads afterwards, and SaveChanges or replacing the whole JSON property writes the null.", "oracle": "exception", "surfaces": [ "*Range.Empty", diff --git a/test/oracles/seeds/compareto-null-operand-compared-as-sql-null.patch b/test/oracles/seeds/compareto-null-operand-compared-as-sql-null.patch index c67d9de8..c5fa4847 100644 --- a/test/oracles/seeds/compareto-null-operand-compared-as-sql-null.patch +++ b/test/oracles/seeds/compareto-null-operand-compared-as-sql-null.patch @@ -2,17 +2,17 @@ Seed: CompareTo against a null range is left to EF Core's rewrite, so a query co Oracles: RangeOrderParityTests Fails: every CompareTo comparison with a null operand that memory answers true (> 0, >= 0, != 0), which returns no rows History: found by the pre-tag analysis (#179), fixed before 10.0.0 shipped (#220) - diff --git a/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs b/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs -index 3c3b2f9..d36cb56 100644 +index 9fc15ab..992c5df 100644 --- a/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs +++ b/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs -@@ -37,7 +37,7 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte +@@ -39,8 +39,7 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte public Expression QueryCompilationStarting(Expression queryExpression, QueryExpressionEventData eventData) => CollectionParameterExpander.Expand( RangeVariantConstantRetyper.Instance.Visit( -- NullOperandCompareToRewriter.Instance.Visit(RangeSetOperatorRewriter.Instance.Visit(queryExpression))), -+ RangeSetOperatorRewriter.Instance.Visit(queryExpression)), +- NullOperandCompareToRewriter.Instance.Visit( +- RangeSetContainsRewriter.Instance.Visit(RangeSetOperatorRewriter.Instance.Visit(queryExpression)))), ++ RangeSetContainsRewriter.Instance.Visit(RangeSetOperatorRewriter.Instance.Visit(queryExpression))), DefaultCollectionMode(eventData.Context)); private static ParameterTranslationMode DefaultCollectionMode(DbContext? context) diff --git a/test/oracles/seeds/compareto-null-rewritten-only-against-zero.patch b/test/oracles/seeds/compareto-null-rewritten-only-against-zero.patch index 841359fa..eb68f2e2 100644 --- a/test/oracles/seeds/compareto-null-rewritten-only-against-zero.patch +++ b/test/oracles/seeds/compareto-null-rewritten-only-against-zero.patch @@ -2,9 +2,8 @@ Seed: CompareTo with a null range is rewritten only when compared with 0 and onl Oracles: RangeOrderParityTests Fails: CompareTo(null) == 1, >= 1, > -1, != -1 and 1 == CompareTo(null) (no rows, memory every row), and a NULL column, which Comparer.Default orders equal to null and before every range History: found by the final pre-release analysis (#256, #261) before 10.0.0 shipped - diff --git a/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs b/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs -index 284394f..3c3b2f9 100644 +index 9fc15ab..82d169d 100644 --- a/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs +++ b/src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs @@ -20,8 +20,8 @@ namespace CodoMetis.ValueRanges.EntityFrameworkCore.PostgreSQL.Query; @@ -15,10 +14,10 @@ index 284394f..3c3b2f9 100644 -/// either side answer in SQL as Comparer<T>.Default does — see . +/// . A fourth makes CompareTo against a null range +/// answer in SQL as it does in memory — see . + /// A fifth keeps RangeSet.Contains out of EF Core's own rewrite of Contains on a + /// read-only collection — see . /// - /// - /// The value set refusals — a server-computed Union consumed by an order- or -@@ -184,28 +184,24 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte +@@ -189,28 +189,24 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte } /// @@ -60,7 +59,7 @@ index 284394f..3c3b2f9 100644 /// /// private sealed class NullOperandCompareToRewriter : ExpressionVisitor -@@ -214,117 +210,61 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte +@@ -219,117 +215,61 @@ public sealed class ValueRangesQueryExpressionInterceptor : IQueryExpressionInte protected override Expression VisitBinary(BinaryExpression node) {