fix: respect maybe-null attributes#2194
Merged
Merged
Conversation
latonz
force-pushed
the
2192-respect-maybenull
branch
2 times, most recently
from
March 20, 2026 07:43
8419bbe to
3e2598c
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes nullability handling in Mapperly by making the generator respect [MaybeNull] when determining whether a member can produce/accept nulls, addressing CS8601 scenarios like #2192.
Changes:
- Add a centralized
SymbolAccessor.IsNullable(ISymbol)which treats fields/properties/constructor parameters as nullable when their type is nullable or they have[MaybeNull]. - Update member wrappers (property/field/ctor-parameter members) to use the centralized nullability logic.
- Add regression tests covering
MaybeNullcombinations and document the behavior change for v5.0.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Riok.Mapperly.Tests/Mapping/ObjectPropertyNullableTest.cs | Adds regression tests for [MaybeNull] source/target property combinations. |
| src/Riok.Mapperly/Symbols/Members/PropertyMember.cs | Switches IsNullable to use SymbolAccessor.IsNullable (but introduces an unused using). |
| src/Riok.Mapperly/Symbols/Members/FieldMember.cs | Switches IsNullable to use SymbolAccessor.IsNullable (but introduces an unused using). |
| src/Riok.Mapperly/Symbols/Members/ConstructorParameterMember.cs | Switches IsNullable to use SymbolAccessor.IsNullable. |
| src/Riok.Mapperly/Descriptors/SymbolAccessor.cs | Implements IsNullable(ISymbol) and adds a safe TryHasAttribute(ISymbol) helper. |
| docs/docs/breaking-changes/5-0.md | Notes that [MaybeNull] is now respected for relevant members. |
Comments suppressed due to low confidence (2)
src/Riok.Mapperly/Symbols/Members/PropertyMember.cs:3
using System.Diagnostics.CodeAnalysis;appears to be unused in this file after the changes. Please remove it to avoid unnecessary-using warnings (and potential build failures if warnings are treated as errors).
using System.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
src/Riok.Mapperly/Symbols/Members/FieldMember.cs:3
using System.Diagnostics.CodeAnalysis;appears to be unused in this file after the changes. Please remove it to avoid unnecessary-using warnings (and potential build failures if warnings are treated as errors).
using System.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
latonz
force-pushed
the
2192-respect-maybenull
branch
from
March 20, 2026 09:02
3e2598c to
b265016
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2192