Skip to content

Commit

Permalink
Add MixedStaticPartialMethodWithNonStaticFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Nov 13, 2023
1 parent 30ff73d commit 44ac9ff
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static ObjectFactoryCollection ExtractObjectFactories(SimpleMappingBuilde
|| methodSymbol.IsPartialDefinition
|| methodSymbol.MethodKind != MethodKind.Ordinary
|| methodSymbol.ReturnsVoid
|| (methodSymbol.IsStatic is false && ctx.Static)
)
{
ctx.ReportDiagnostic(DiagnosticDescriptors.InvalidObjectFactorySignature, methodSymbol, methodSymbol.Name);
Expand Down
2 changes: 2 additions & 0 deletions src/Riok.Mapperly/Descriptors/SimpleMappingBuilderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ protected SimpleMappingBuilderContext(SimpleMappingBuilderContext ctx)

public WellKnownTypes Types => _compilationContext.Types;

public bool Static => _descriptor.Static;

public SymbolAccessor SymbolAccessor { get; }

public AttributeDataAccessor AttributeAccessor { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ public partial class Mapper
.HaveAssertedAllDiagnostics();
}

[Fact]
public void MixedStaticPartialMethodWithNonStaticFactory()
{
var source = TestSourceBuilder.CSharp(
"""
using Riok.Mapperly.Abstractions;
[Mapper]
public partial class CarMapper
{
[ObjectFactory]
B CreateB() => new B();
public static partial B Map(A a);
}
class A { public string StringValue { get; set; } }
class B { public string StringValue { get; set; } }
"""
);

TestHelper
.GenerateMapper(source, TestHelperOptions.AllowAllDiagnostics)
.Should()
.HaveDiagnostic(DiagnosticDescriptors.InvalidObjectFactorySignature)
.HaveAssertedAllDiagnostics();
}

[Fact]
public void MixedStaticMethodWithInstanceMethod()
{
Expand Down

0 comments on commit 44ac9ff

Please sign in to comment.