Skip to content

Commit

Permalink
fix: #589 InvalidOperationException in Vogen 4.0.3
Browse files Browse the repository at this point in the history
Fixes a recently introduced bug where Vogen assumed that the first global attribute in an assembly is the relevant one for it.
  • Loading branch information
SteveDunn committed May 10, 2024
1 parent b6d5f6f commit e11ccd9
Show file tree
Hide file tree
Showing 5 changed files with 673 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Vogen/ManageAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class ManageAttributes
public static VogenConfigurationBuildResult GetDefaultConfigFromGlobalAttribute(
GeneratorAttributeSyntaxContext ctx)
{
var assemblyAttributes = ctx.TargetSymbol.GetAttributes();
var assemblyAttributes = ctx.Attributes;

if (assemblyAttributes.IsDefaultOrEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Shared;
using VerifyXunit;
using Vogen;

Expand All @@ -18,7 +17,7 @@ public async Task Test()
using System;
using Vogen;
public class Test<T> : Attribute { }
[Test<byte[]>]
Expand All @@ -31,18 +30,13 @@ public class Test
public partial struct Vo
{
}
""";
await RunTest(source);
}
""";

private static Task RunTest(string source) =>
new SnapshotRunner<ValueObjectGenerator>()
.WithSource(source)
.IgnoreInitialCompilationErrors()
.RunOnAllFrameworks();

await new SnapshotRunner<ValueObjectGenerator>()
.WithSource(source)
.IgnoreInitialCompilationErrors()
.RunOnAllFrameworks();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Shared;
using VerifyXunit;
using Vogen;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Threading.Tasks;
using Shared;
using VerifyXunit;
using Vogen;

namespace SnapshotTests.BugFixes;

// See https://github.com/SteveDunn/Vogen/issues/589
[UsesVerify]
public class Bug589_Vogen_does_not_ignore_irrelevant_assembly_attributes
{
[Fact]
public async Task Test()
{
var source = """
using System;
using Vogen;
[assembly: Test(1, 2, 3, 4, 5)]
[assembly: VogenDefaults(conversions: Conversions.Default | Conversions.LinqToDbValueConverter)]
[AttributeUsage(AttributeTargets.Assembly)]
#pragma warning disable CS9113 // Parameter 'Values' is unread
public sealed class TestAttribute(params int[] Values) : Attribute
{
}
[ValueObject]
public partial struct Vo
{
}
""";

await new SnapshotRunner<ValueObjectGenerator>()
.WithSource(source)
.IgnoreInitialCompilationErrors()
.RunOn(TargetFramework.Net8_0);
}
}
Loading

0 comments on commit e11ccd9

Please sign in to comment.