Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooling updates #20

Merged
merged 10 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
DOTNET_NOLOGO: 1
TreatWarningsAsErrors: true

jobs:
build:
Expand All @@ -19,7 +20,7 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore /p:TreatWarningsAsErrors=true
run: dotnet build --configuration Release
- name: Run Tests
run: dotnet test --configuration Release --no-build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public CollectingInterpolatedStringHandler(int literalLength, int formattedCount

public CollectingInterpolatedStringHandler()
{
_items = new List<object?>();
_items = [];
}

private readonly List<object?> _items;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class DiscriminatedUnionGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(context => context.AddSource("DiscriminatedUnionAttribute.g.cs", DiscriminatedUnionAttributeSource));
context.RegisterPostInitializationOutput(static context => context.AddSource("DiscriminatedUnionAttribute.g.cs", DiscriminatedUnionAttributeSource));

var code = context.SyntaxProvider.CreateSyntaxProvider(static (node, _) => IsSyntaxTargetForGeneration(node), GetSemanticTargetForGeneration)
.WhereNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>11.0</LangVersion>
<LangVersion>13.0</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
<PropertyGroup Label="NuGet Metadata">
Expand Down Expand Up @@ -35,12 +35,15 @@
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>
<ItemGroup Label="Deterministic Builds and Source Link">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
<!-- Careful! Updating this means that you might break compatibility
with older .NET SDKs and older versions of Visual Studio!
See <https://docs.microsoft.com/en-us/visualstudio/extensibility/roslyn-version-support>
for a detailed compatibility table. -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.0.1" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="PolySharp" Version="1.15.0" PrivateAssets="all" />
</ItemGroup>
</Project>
13 changes: 5 additions & 8 deletions Funcky.DiscriminatedUnion.SourceGeneration/SelectorComparer.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
namespace Funcky.DiscriminatedUnion.SourceGeneration;

internal sealed class SelectorComparer<TSource, TSelected> : IEqualityComparer<TSource>
internal sealed class SelectorComparer<TSource, TSelected>(Func<TSource, TSelected> selector)
: IEqualityComparer<TSource>
{
private readonly Func<TSource, TSelected> _selector;
public bool Equals(TSource x, TSource y) => EqualityComparer<TSelected>.Default.Equals(selector(x), selector(y));

public SelectorComparer(Func<TSource, TSelected> selector) => _selector = selector;

public bool Equals(TSource x, TSource y) => EqualityComparer<TSelected>.Default.Equals(_selector(x), _selector(y));

public int GetHashCode(TSource obj) => EqualityComparer<TSelected>.Default.GetHashCode(_selector(obj));
}
public int GetHashCode(TSource obj) => EqualityComparer<TSelected>.Default.GetHashCode(selector(obj));
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Verify.SourceGenerators" Version="1.2.0" />
<PackageReference Include="Verify.Xunit" Version="14.14.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
<PackageReference Include="Verify.Xunit" Version="28.9.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Sources/*.cs" />
Expand Down
5 changes: 1 addition & 4 deletions Funcky.DiscriminatedUnion.Test/ModuleInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ namespace Funcky.DiscriminatedUnion.Test;
public static class ModuleInitializer
{
[ModuleInitializer]
public static void Init()
{
VerifySourceGenerators.Enable();
}
public static void Init() => VerifySourceGenerators.Initialize();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: DiscriminatedUnionGenerator.g.cs
//HintName: DiscriminatedUnionGenerator.g.cs
// <auto-generated/>
#nullable enable

Expand All @@ -14,18 +14,18 @@ partial class StaticClass
{
partial record NestedUnion
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract TResult Match<TResult>(global::System.Func<Variant, TResult> variant);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract void Switch(global::System.Action<Variant> variant);

partial record Variant
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override TResult Match<TResult>(global::System.Func<Variant, TResult> variant) => variant(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override void Switch(global::System.Action<Variant> variant) => variant(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//HintName: DiscriminatedUnionGenerator.g.cs
//HintName: DiscriminatedUnionGenerator.g.cs
// <auto-generated/>
#nullable enable

partial record EmptyUnion
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract TResult Match<TResult>();

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract void Switch();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ namespace Funcky.DiscriminatedUnion.Test
{
partial record FlattenedNestedUnionWithPartition
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Literal.Number.Integer, TResult> integer);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract void Switch(global::System.Action<Keyword> keyword, global::System.Action<Literal.Number.Integer> integer);

partial record Keyword
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Literal.Number.Integer, TResult> integer) => keyword(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override void Switch(global::System.Action<Keyword> keyword, global::System.Action<Literal.Number.Integer> integer) => keyword(this);
}

Expand All @@ -27,17 +27,17 @@ partial record Number
{
partial record Integer
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Literal.Number.Integer, TResult> integer) => integer(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override void Switch(global::System.Action<Keyword> keyword, global::System.Action<Literal.Number.Integer> integer) => integer(this);
}
}
}
}

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public static partial class FlattenedNestedUnionWithPartitionEnumerableExtensions
{
public static (global::System.Collections.Generic.IReadOnlyList<FlattenedNestedUnionWithPartition.Keyword> Keyword, global::System.Collections.Generic.IReadOnlyList<FlattenedNestedUnionWithPartition.Literal.Number.Integer> Integer) Partition(this global::System.Collections.Generic.IEnumerable<FlattenedNestedUnionWithPartition> source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ namespace Funcky.DiscriminatedUnion.Test
{
partial record FlattenedUnionWithPartition
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Integer, TResult> integer);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public abstract void Switch(global::System.Action<Keyword> keyword, global::System.Action<Integer> integer);

partial record Keyword
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Integer, TResult> integer) => keyword(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override void Switch(global::System.Action<Keyword> keyword, global::System.Action<Integer> integer) => keyword(this);
}

partial record Integer
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override TResult Match<TResult>(global::System.Func<Keyword, TResult> keyword, global::System.Func<Integer, TResult> integer) => integer(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public override void Switch(global::System.Action<Keyword> keyword, global::System.Action<Integer> integer) => integer(this);
}
}

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
public static partial class FlattenedUnionWithPartitionEnumerableExtensions
{
public static (global::System.Collections.Generic.IReadOnlyList<FlattenedUnionWithPartition.Keyword> Keyword, global::System.Collections.Generic.IReadOnlyList<FlattenedUnionWithPartition.Integer> Integer) Partition(this global::System.Collections.Generic.IEnumerable<FlattenedUnionWithPartition> source)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
//HintName: DiscriminatedUnionGenerator.g.cs
//HintName: DiscriminatedUnionGenerator.g.cs
// <auto-generated/>
#nullable enable

namespace Funcky.DiscriminatedUnion.Test
{
partial record Result<T> where T : notnull
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal abstract TResult Match<TResult>(global::System.Func<Ok, TResult> ok, global::System.Func<Error, TResult> error);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal abstract void Switch(global::System.Action<Ok> ok, global::System.Action<Error> error);

partial record Ok
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal override TResult Match<TResult>(global::System.Func<Ok, TResult> ok, global::System.Func<Error, TResult> error) => ok(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal override void Switch(global::System.Action<Ok> ok, global::System.Action<Error> error) => ok(this);
}

partial record Error
{
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal override TResult Match<TResult>(global::System.Func<Ok, TResult> ok, global::System.Func<Error, TResult> error) => error(this);

[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "1.2.1.0")]
[global::System.CodeDom.Compiler.GeneratedCode("Funcky.DiscriminatedUnion.SourceGeneration", "VERSION")]
internal override void Switch(global::System.Action<Ok> ok, global::System.Action<Error> error) => error(this);
}
}
Expand Down
Loading