Skip to content

Enable nullable annotations in precompiled query interceptors - #39224

Open
nurullahturkoglu wants to merge 1 commit into
dotnet:mainfrom
nurullahturkoglu:fix/precompiled-nullable-37996
Open

nurullahturkoglu wants to merge 1 commit into
dotnet:mainfrom
nurullahturkoglu:fix/precompiled-nullable-37996

Conversation

@nurullahturkoglu

Copy link
Copy Markdown

Fixes #37996

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

I posted the plan in #37996 (comment) but haven't heard back from the team yet, so the second box is unchecked.

Description

The generated interceptors file starts with // <auto-generated />, so the compiler disables the nullable context for it, but the interceptor signatures keep the nullable annotations of the operators they intercept (e.g. TSource? for FirstOrDefault). This produces CS8669 in the user's project regardless of its Nullable setting.

The generator now emits #nullable enable annotations after the #pragma warning disable EF9100 line. This makes the annotations valid without enabling nullable warnings for the rest of the generated code.

Testing

PrecompiledQueryTestHelpers.Test now fails if the generated files produce CS8669, so every precompiled query test checks it.

  • Without the fix, 33 of 155 tests in PrecompiledQuerySqliteTest and AdHocPrecompiledQuerySqliteTest fail, and 43 in the SQL Server precompiled test classes.
  • With the fix, the SQLite and SQL Server precompiled query tests pass (SQL Server ran against a local Linux container on macOS), as do EFCore.Design.Tests and the full EFCore.Sqlite.FunctionalTests.

I haven't run the tests on Windows.

- Emit #nullable enable annotations in the generated interceptors file, which has the nullable context disabled because it is marked auto-generated
- Fail precompiled query tests when the generated code produces CS8669

Fixes dotnet#37996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Precompiled queries code produces nullable annotation warning on build

1 participant