Skip to content

fix: respect maybe-null attributes#2194

Merged
latonz merged 1 commit into
riok:mainfrom
latonz:2192-respect-maybenull
Mar 20, 2026
Merged

fix: respect maybe-null attributes#2194
latonz merged 1 commit into
riok:mainfrom
latonz:2192-respect-maybenull

Conversation

@latonz

@latonz latonz commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Closes #2192

@latonz latonz self-assigned this Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 07:39
@latonz latonz added bug Something isn't working breaking-change This issue or pull request will break existing consumers labels Mar 20, 2026
@latonz
latonz force-pushed the 2192-respect-maybenull branch 2 times, most recently from 8419bbe to 3e2598c Compare March 20, 2026 07:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MaybeNull combinations 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
latonz force-pushed the 2192-respect-maybenull branch from 3e2598c to b265016 Compare March 20, 2026 09:02
@latonz
latonz merged commit f866427 into riok:main Mar 20, 2026
17 checks passed
@latonz
latonz deleted the 2192-respect-maybenull branch March 20, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change This issue or pull request will break existing consumers bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CS8601 while mapping properties annotated with MaybeNullAttribute

2 participants