From ea7769a71e54cedf057cf9e1907fe315f285c0af Mon Sep 17 00:00:00 2001 From: Petar Isakovic Date: Thu, 16 Apr 2026 12:00:02 -0400 Subject: [PATCH 1/3] UnionType Update --- Directory.Packages.props | 1 - src/Directory.Build.props | 1 + .../CompilerServices/UnionAttribute.cs | 7 +++ .../AsyncToSyncRewriter.cs | 8 ++-- src/Zomp.SyncMethodGenerator/Operation.cs | 48 ++++++++++++++++--- .../Zomp.SyncMethodGenerator.csproj | 1 - 6 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 src/System/Runtime/CompilerServices/UnionAttribute.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 1c04406..5669112 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,7 +10,6 @@ - diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 7f335b9..fd0742d 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -23,6 +23,7 @@ + diff --git a/src/System/Runtime/CompilerServices/UnionAttribute.cs b/src/System/Runtime/CompilerServices/UnionAttribute.cs new file mode 100644 index 0000000..6412530 --- /dev/null +++ b/src/System/Runtime/CompilerServices/UnionAttribute.cs @@ -0,0 +1,7 @@ +namespace System.Runtime.CompilerServices; + +/// +/// Marks a type as a C# union. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] +public sealed class UnionAttribute : Attribute; diff --git a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs index 119e81c..5d57ca8 100644 --- a/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs +++ b/src/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs @@ -376,8 +376,8 @@ bool IsValidParameter(ParameterSyntax ps, int i) var extra = ProcessTrivia(leading, ds); if (extra is not null && extra.AdditionalStatements.Count > 0) { - modifications.Add(i, new List(extra.AdditionalStatements)); - modifications.Add(i + 1, true); + modifications.Add(i, new Operation([.. extra.AdditionalStatements])); + modifications.Add(i + 1, new Operation(true)); } if (semanticModel.GetDeclaredSymbol(ps) is not { } symbol) @@ -1074,8 +1074,8 @@ bool ShouldRemoveArgumentLocal(ArgumentSyntax arg, int index) if (extra is { AdditionalStatements.Count: > 0 }) { - modifications.Add(index, new List(extra.AdditionalStatements)); - modifications.Add(index + 1, true); + modifications.Add(index, new Operation([.. extra.AdditionalStatements])); + modifications.Add(index + 1, new Operation(true)); } if (byExpression || nullableParameters is not { } parameters) diff --git a/src/Zomp.SyncMethodGenerator/Operation.cs b/src/Zomp.SyncMethodGenerator/Operation.cs index c810f58..9e3000c 100644 --- a/src/Zomp.SyncMethodGenerator/Operation.cs +++ b/src/Zomp.SyncMethodGenerator/Operation.cs @@ -1,7 +1,41 @@ -namespace Zomp.SyncMethodGenerator; - -[N.SourceGenerators.UnionTypes.UnionType(typeof(List), "NewStatements")] -[N.SourceGenerators.UnionTypes.UnionType(typeof(bool), "RemoveLeadingEndIf")] -internal sealed partial class Operation -{ -} +namespace Zomp.SyncMethodGenerator; + +/// +/// Represents a sync-only operation. +/// +[Union] +internal readonly struct Operation +{ + /// + /// Initializes a new instance of the struct. + /// + /// The new statements to insert. + public Operation(List value) + { + Value = value; + } + + /// + /// Initializes a new instance of the struct. + /// + /// A value indicating whether to remove the leading end-if directive. + public Operation(bool value) + { + Value = value; + } + + /// + /// Gets the active operation value. + /// + public object? Value { get; } + + /// + /// Gets a value indicating whether the operation inserts new statements. + /// + public bool IsNewStatements => Value is List; + + /// + /// Gets the operation value as new statements. + /// + public List AsNewStatements => (List)Value!; +} diff --git a/src/Zomp.SyncMethodGenerator/Zomp.SyncMethodGenerator.csproj b/src/Zomp.SyncMethodGenerator/Zomp.SyncMethodGenerator.csproj index a6faef9..cb8de0c 100644 --- a/src/Zomp.SyncMethodGenerator/Zomp.SyncMethodGenerator.csproj +++ b/src/Zomp.SyncMethodGenerator/Zomp.SyncMethodGenerator.csproj @@ -49,7 +49,6 @@ - From e3a49f335705bda5cb993338822f8329fbacbc22 Mon Sep 17 00:00:00 2001 From: Petar Isakovic Date: Thu, 16 Apr 2026 12:04:19 -0400 Subject: [PATCH 2/3] format fix --- src/System/Runtime/CompilerServices/UnionAttribute.cs | 2 +- src/Zomp.SyncMethodGenerator/Operation.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System/Runtime/CompilerServices/UnionAttribute.cs b/src/System/Runtime/CompilerServices/UnionAttribute.cs index 6412530..e4ebabf 100644 --- a/src/System/Runtime/CompilerServices/UnionAttribute.cs +++ b/src/System/Runtime/CompilerServices/UnionAttribute.cs @@ -1,4 +1,4 @@ -namespace System.Runtime.CompilerServices; +namespace System.Runtime.CompilerServices; /// /// Marks a type as a C# union. diff --git a/src/Zomp.SyncMethodGenerator/Operation.cs b/src/Zomp.SyncMethodGenerator/Operation.cs index 9e3000c..5e4e731 100644 --- a/src/Zomp.SyncMethodGenerator/Operation.cs +++ b/src/Zomp.SyncMethodGenerator/Operation.cs @@ -1,4 +1,4 @@ -namespace Zomp.SyncMethodGenerator; +namespace Zomp.SyncMethodGenerator; /// /// Represents a sync-only operation. From 4c0633ae5787866803205ddb5c48dd923fedc528 Mon Sep 17 00:00:00 2001 From: Petar Isakovic Date: Thu, 16 Apr 2026 14:43:27 -0400 Subject: [PATCH 3/3] Fix union source line endings --- .../CompilerServices/UnionAttribute.cs | 14 ++-- src/Zomp.SyncMethodGenerator/Operation.cs | 82 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/System/Runtime/CompilerServices/UnionAttribute.cs b/src/System/Runtime/CompilerServices/UnionAttribute.cs index e4ebabf..ec9a01f 100644 --- a/src/System/Runtime/CompilerServices/UnionAttribute.cs +++ b/src/System/Runtime/CompilerServices/UnionAttribute.cs @@ -1,7 +1,7 @@ -namespace System.Runtime.CompilerServices; - -/// -/// Marks a type as a C# union. -/// -[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] -public sealed class UnionAttribute : Attribute; +namespace System.Runtime.CompilerServices; + +/// +/// Marks a type as a C# union. +/// +[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false)] +public sealed class UnionAttribute : Attribute; diff --git a/src/Zomp.SyncMethodGenerator/Operation.cs b/src/Zomp.SyncMethodGenerator/Operation.cs index 5e4e731..5d2e4a3 100644 --- a/src/Zomp.SyncMethodGenerator/Operation.cs +++ b/src/Zomp.SyncMethodGenerator/Operation.cs @@ -1,41 +1,41 @@ -namespace Zomp.SyncMethodGenerator; - -/// -/// Represents a sync-only operation. -/// -[Union] -internal readonly struct Operation -{ - /// - /// Initializes a new instance of the struct. - /// - /// The new statements to insert. - public Operation(List value) - { - Value = value; - } - - /// - /// Initializes a new instance of the struct. - /// - /// A value indicating whether to remove the leading end-if directive. - public Operation(bool value) - { - Value = value; - } - - /// - /// Gets the active operation value. - /// - public object? Value { get; } - - /// - /// Gets a value indicating whether the operation inserts new statements. - /// - public bool IsNewStatements => Value is List; - - /// - /// Gets the operation value as new statements. - /// - public List AsNewStatements => (List)Value!; -} +namespace Zomp.SyncMethodGenerator; + +/// +/// Represents a sync-only operation. +/// +[Union] +internal readonly struct Operation +{ + /// + /// Initializes a new instance of the struct. + /// + /// The new statements to insert. + public Operation(List value) + { + Value = value; + } + + /// + /// Initializes a new instance of the struct. + /// + /// A value indicating whether to remove the leading end-if directive. + public Operation(bool value) + { + Value = value; + } + + /// + /// Gets the active operation value. + /// + public object? Value { get; } + + /// + /// Gets a value indicating whether the operation inserts new statements. + /// + public bool IsNewStatements => Value is List; + + /// + /// Gets the operation value as new statements. + /// + public List AsNewStatements => (List)Value!; +}