Skip to content

fix: align generated nullable policy with consuming project - #50

Merged
ycherkes merged 3 commits into
mainfrom
feature/project-level-nullable-policy
Sep 2, 2026
Merged

ycherkes merged 3 commits into
mainfrom
feature/project-level-nullable-policy

Conversation

@ycherkes

@ycherkes ycherkes commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Make generated nullable handling project-level

Summary

AlephMapper-generated mapper files now follow the consuming project's NullableContextOptions rather than the source-local #nullable state of individual mapping methods or inlined helpers.

Each generated mapper file emits one file-level #nullable restore immediately after its auto-generated header. This restores the project's nullable configuration for Roslyn-generated source trees, which otherwise default to nullable-disabled behavior.

Changes

  • Removed nullable directives from generated-member framing.
  • Simplified NullablePolicy to map project-level Enable, Disable, Warnings, and Annotations modes.
  • Kept nullable-aware type rendering driven by the project policy.
  • Suppress nullable reference syntax, including class? constraints, when project annotations are disabled.
  • Removed automatic null-forgiving operators from null-conditional Ignore and Rewrite output. Genuine nullable-flow diagnostics are no longer hidden by generated ! or null! syntax.
  • Updated generated baselines and documented the behavior in the README.

Tests

  • Added coverage for all four NullableContextOptions modes, independently modeling source annotations and expected generated annotations.
  • Added a nullable-sensitive mixed-context helper test. It verifies helper directives are not propagated and that an expected generated CS8602 warning is not silently suppressed under project nullable Enable.
  • Confirmed generated mapper output has a single file-level #nullable restore and no member-level nullable directives.

Nullable-flow behavior

  • Enable: generated annotations are emitted and nullable-flow warnings may surface.
  • Disable: generated annotations and nullable-flow warnings are disabled.
  • Warnings: generated annotations are omitted while nullable-flow warnings may surface.
  • Annotations: generated annotations are emitted while nullable-flow warnings are disabled.

The solution build now reports two legitimate CS8600 warnings from existing generated Experiment code. They are intentionally not suppressed: generated code follows the consuming project's nullable-warning policy.

Validation

  • dotnet build AlephMapper.slnx --configuration Release
  • dotnet run --project tests/AlephMapper.Tests/AlephMapper.Tests.csproj -c Release — 60 passed
  • dotnet test AlephMapper.slnx --configuration Release — 97 passed
  • dotnet pack source/AlephMapper.csproj --configuration Release --output artifacts/nuget
  • Package smoke build using <Nullable>enable</Nullable>

@ycherkes
ycherkes merged commit 133caa5 into main Sep 2, 2026
1 check passed
@ycherkes
ycherkes deleted the feature/project-level-nullable-policy branch September 2, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant