Skip to content

Commit

Permalink
feat: fix incorrect private set when ~MemberVisibility.Accessible
Browse files Browse the repository at this point in the history
… is used
  • Loading branch information
TimothyMakkison committed Nov 20, 2023
1 parent 21fdc99 commit f382477
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Riok.Mapperly/Symbols/SetterMemberPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public static SetterMemberPath Build(MappingBuilderContext ctx, MemberPath membe

private static (IMappableMember, bool) BuildMemberSetter(MappingBuilderContext ctx, IMappableMember member)
{
if (ctx.SymbolAccessor.IsDirectlyAccessible(member.MemberSymbol))
{
if (ctx.SymbolAccessor.IsDirectlyAccessible(member.MemberSymbol) && member.CanSetDirectly)
return (member, false);
}

if (member.MemberSymbol.Kind == SymbolKind.Field)
{
Expand Down
24 changes: 24 additions & 0 deletions test/Riok.Mapperly.Tests/Mapping/UnsafeAccessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ public void ManualUnflattenedPropertyNullablePath()
);
}

[Fact]
public void PropertyWithPrivateSetter()
{
var source = TestSourceBuilder.MapperWithBodyAndTypes(
"""
partial B Map(A source);
""",
TestSourceBuilderOptions.WithMemberVisibility(MemberVisibility.All),
"class A { public int Value { get; set; } }",
"class B { public int Value { get; private set; } }"
);

TestHelper
.GenerateMapper(source)
.Should()
.HaveMapMethodBody(
"""
var target = new global::B();
target.SetValue(source.Value);
return target;
"""
);
}

[Fact]
public Task PrivateField()
{
Expand Down

0 comments on commit f382477

Please sign in to comment.