Polymorphic dispatch support#74
Conversation
|
EFNext/EntityFrameworkCore.Projectables#215 uses compile time polymorphic dispatch which I discourage for reasons that I've disclosed in that PR. For this project, runtime polymorphic dispatch seems the right way to go about things |
There was a problem hiding this comment.
Pull request overview
Adds runtime polymorphic dispatch for virtual/override [Expressive] members so expression expansion can choose the override body based on the runtime type (via is / conditional chains), with configuration support to disable this behavior and new integration/regression tests across providers. This also retires the EXP0024 generator diagnostic and introduces EXP0032 to warn when a derived override forgets [Expressive], along with a code fix.
Changes:
- Implement polymorphic dispatch expansion in
ExpressiveReplacerplus an opt-out switch inExpressiveOptions/ EF Core options wiring. - Retire EXP0024 and add EXP0032 analyzer + code-fix support; update docs accordingly.
- Add/expand integration and generator tests covering polymorphic dispatch behavior and provider translation.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ExpressiveSharp.IntegrationTests/Tests/ExpansionEdgeCasesTests.cs | Adds edge-case tests validating polymorphic dispatch for virtual methods/properties and the disable switch. |
| tests/ExpressiveSharp.IntegrationTests/Scenarios/Store/Models/LineItem.cs | Updates regression comment for virtual member with no overrides; removes EXP0024 suppression. |
| tests/ExpressiveSharp.Generator.Tests/ExpressiveGenerator/InterfaceTests.cs | Updates expectations now that EXP0024 is retired. |
| tests/ExpressiveSharp.Generator.Tests/ExpressiveGenerator/DiagnosticTests.cs | Updates diagnostic tests to assert EXP0024 is no longer produced. |
| tests/ExpressiveSharp.Generator.Tests/CodeFixers/OverrideMissingExpressiveAnalyzerTests.cs | Adds tests for new EXP0032 analyzer and code fix behavior. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/SqlServer/PolymorphicDispatchTests.cs | Provider-specific fixture for polymorphic dispatch EF Core tests (SQL Server). |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/Sqlite/PolymorphicDispatchTests.cs | Provider-specific fixture for polymorphic dispatch EF Core tests (SQLite). |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/Sqlite/PolymorphicDispatchDisabledTests.cs | Verifies EF Core translation when polymorphic dispatch is disabled. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/Postgres/PolymorphicDispatchTests.cs | Provider-specific fixture for polymorphic dispatch EF Core tests (Postgres). |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Tests/PomeloMySql/PolymorphicDispatchTests.cs | Provider-specific fixture for polymorphic dispatch EF Core tests (Pomelo MySQL). |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/PolymorphicTestDbContext.cs | Adds TPH model used by EF Core polymorphic dispatch tests. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Models/Animal.cs | Defines Animal/Dog/Cat hierarchy with virtual/override [Expressive] member used for dispatch testing. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Infrastructure/TestContextFactories.cs | Adds context factories for the new polymorphic dispatch DbContext across providers. |
| tests/ExpressiveSharp.EntityFrameworkCore.IntegrationTests/Infrastructure/PolymorphicDispatchTestBase.cs | Shared EF Core assertions ensuring translation and correct per-row override selection. |
| src/ExpressiveSharp/Services/ExpressiveReplacer.cs | Implements polymorphic dispatch planning and expansion via runtime type-test chains. |
| src/ExpressiveSharp/Services/ExpressiveOptions.cs | Adds a thread-safe option to disable polymorphic dispatch and a getter to read the setting. |
| src/ExpressiveSharp/Extensions/ExpressionExtensions.cs | Threads the polymorphic dispatch flag into ExpressiveReplacer during expansion. |
| src/ExpressiveSharp.Generator/Infrastructure/Diagnostics.cs | Retires EXP0024 (descriptor removed; ID reserved). |
| src/ExpressiveSharp.Generator/ExpressiveGenerator.cs | Stops reporting EXP0024 for virtual/abstract/override [Expressive] members. |
| src/ExpressiveSharp.EntityFrameworkCore/Infrastructure/Internal/ExpressiveOptionsExtension.cs | Wires disable-polymorphic-dispatch into the DI-created ExpressiveOptions. |
| src/ExpressiveSharp.EntityFrameworkCore/Extensions/DbContextOptionsExtensions.cs | Passes the new disable flag through the EF Core options extension. |
| src/ExpressiveSharp.EntityFrameworkCore/ExpressiveOptionsBuilder.cs | Adds DisablePolymorphicDispatch() configuration for EF Core consumers. |
| src/ExpressiveSharp.CodeFixers/OverrideMissingExpressiveAnalyzer.cs | Introduces EXP0032 analyzer for overrides missing [Expressive] (with [NotExpressive] opt-out). |
| src/ExpressiveSharp.CodeFixers/AddExpressiveCodeFixProvider.cs | Extends existing code fix provider to also fix EXP0032. |
| docs/reference/diagnostics.md | Marks EXP0024 as retired and documents EXP0032. |
| docs/advanced/limitations.md | Updates limitations guidance to describe runtime polymorphic dispatch, opt-out, and caveats. |
| CLAUDE.md | Updates internal repo overview to reflect polymorphic dispatch and diagnostic changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f9a4b98 to
c8ddf4e
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Introduce support for polymorphic dispatch in the Expressive framework, allowing runtime resolution of virtual members. This includes enhancements to the options configuration and the addition of integration tests for various database providers.