SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
887 stars 46 forks source link

`InvalidOperationException` in Vogen 4.0.3 #589

Closed viceroypenguin closed 6 months ago

viceroypenguin commented 6 months ago

Describe the bug

If an assembly: attribute with a single params parameter is used with multiple values before the assembly: VogenDefaults attribute in the same file, then the following warning is generated:

warning CS8785: Generator 'ValueObjectGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidOperationException' with message 'TypedConstant is an array. Use Values property.'.

Products:

Steps to reproduce

In a blank project, use the following code

using Vogen;

[assembly: Test(1, 2, 3, 4)]

[assembly: VogenDefaults(conversions: Conversions.Default | Conversions.LinqToDbValueConverter)]

Console.WriteLine("Test");

[AttributeUsage(AttributeTargets.Assembly)]
public sealed class TestAttribute(params int[] Values) : Attribute;

[ValueObject]
public readonly partial record struct TestId;

Expected behaviour

The [assembly: Test(1, 2, 3, 4)] will have no impact on the VogenDefaults attribute.

NB: switching the order, so that the Test attribute comes after VogenDefaults causes the build to work successfully.

SteveDunn commented 6 months ago

Thanks for the bug and repo - well spotted! I'll get this fixed ASAP

SteveDunn commented 6 months ago

Thanks for the bug and repo - well spotted! I'll get this fixed ASAP

Will be in 4.0.4 tomorrow - thanks again!

viceroypenguin commented 6 months ago

Thanks!