Skip to content

Commit

Permalink
Merge pull request #578 from SteveDunn/575-fix-for-when-project-conta…
Browse files Browse the repository at this point in the history
…ins-a-generic-attribute-of-array-type

Fix for when project contains a generic attribute of array type
  • Loading branch information
SteveDunn authored Apr 28, 2024
2 parents 49795e3 + e3f8790 commit c701f3e
Show file tree
Hide file tree
Showing 10 changed files with 3,149 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Vogen/SemanticHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ static class SemanticHelper

var prefix = FullNamespace(symbol);
var suffix = "";

if (symbol.Arity > 0)
{
suffix = $"<{string.Join(", ", symbol.TypeArguments.Select(targ => FullName((INamedTypeSymbol) targ)))}>";
suffix = $"<{string.Join(", ", symbol.TypeArguments.Select(a => FullName(a as INamedTypeSymbol)))}>";
}

if (prefix != "")
Expand Down
20 changes: 20 additions & 0 deletions tests/ConsumerTests/BugFixTests/Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace ConsumerTests.BugFixTests;

// There are no particular tests for this. The fact that it compiles without an issue
public class Test<T> : Attribute { }

[Test<byte[]>]
public class Foo { }

[ValueObject]
public partial struct Vo { }

public class Bar
{
public Bar()
{
Vo.From(123);
}
}


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

namespace SnapshotTests.BugFixes;

// See https://github.com/SteveDunn/Vogen/issues/575
[UsesVerify]
public class Bug575_AttributesWithArraysBreaksGenerator
{
// Previously, any attribute found with an array as a parameter caused an
// InvalidCastException in Vogen and stopped the generator.
[Fact]
public async Task Test()
{
var source = """

using System;
using Vogen;

public class Test<T> : Attribute { }

[Test<byte[]>]
public class Test
{
Test() => Vo.From(123);
}

[ValueObject]
public partial struct Vo
{
}


""";

await RunTest(source);
}


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

}
Loading

0 comments on commit c701f3e

Please sign in to comment.