Skip to content

Commit

Permalink
- fix warnigs
Browse files Browse the repository at this point in the history
  • Loading branch information
ax0l0tl committed Dec 18, 2023
1 parent 58a77f9 commit 9a38b38
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class Generator
{
var resultTypeNameFullName = resultTypeSchema.ResultType.FullTypeName().Replace('.', '_');
var resultTypeFullNameWithNamespace = resultTypeSchema.ResultType.FullTypeNameWithNamespace();
var resultTypeNamespace = resultTypeSchema.ResultType.GetFullNamespace();
var resultTypeNamespace = resultTypeSchema.ResultType.GetFullNamespace()!;

var errorTypeNameFullName = resultTypeSchema.ErrorType?.FullTypeNameWithNamespace() ?? typeof(string).FullName;

Expand All @@ -44,7 +44,7 @@ string Replace(string code, params string[] additionalNamespaces)
.Append(resultTypeNamespace)
.Distinct()
.Select(a => $"using {a};")
.ToSeparatedString(Environment.NewLine));
.ToSeparatedString("\n"));
return code;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ string Replace(string code, params string[] additionalNamespaces)
.Append(unionTypeNamespace)
.Distinct()
.Select(a => $"using {a};")
.ToSeparatedString(Environment.NewLine));
.ToSeparatedString("\n"));
return code;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>

<VersionSuffixLocal />
<!--When variable is set we are building a prerelease package-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static async Task Switch(this Task<FunicularSwitch.Generators.Consumer.Wi

public abstract partial class WithPrimaryConstructor
{
public static FunicularSwitch.Generators.Consumer.WithPrimaryConstructor DerivedWithPrimaryConstructor(string Blubs, int test) => new FunicularSwitch.Generators.Consumer.DerivedWithPrimaryConstructor(Blubs, test);
public static FunicularSwitch.Generators.Consumer.WithPrimaryConstructor DerivedWithPrimaryConstructor(string message, int test) => new FunicularSwitch.Generators.Consumer.DerivedWithPrimaryConstructor(message, test);
}
}
#pragma warning restore 1591
13 changes: 10 additions & 3 deletions Source/Tests/FunicularSwitch.Generators.Consumer/GeneratorSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ select x
[TestMethod]
public void TestFactoryMethodsForClassesWithPrimaryConstructor()
{
var _ = WithPrimaryConstructor.DerivedWithPrimaryConstructor("Hallo", 42);
var x = WithPrimaryConstructor.DerivedWithPrimaryConstructor("Hallo", 42);
Console.WriteLine($"Created {x.Match(d => $"{d.Message} {d.Test}")}");
}
}

Expand Down Expand Up @@ -278,6 +279,12 @@ public override bool Equals(object? obj)
}

[UnionType]
public abstract partial class WithPrimaryConstructor(int Test);
public abstract partial class WithPrimaryConstructor(int test)
{
public int Test { get; } = test;
}

public class DerivedWithPrimaryConstructor(string Blubs, int test) : WithPrimaryConstructor(test);
public class DerivedWithPrimaryConstructor(string message, int test) : WithPrimaryConstructor(test)
{
public string Message { get; } = message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Testing.Verifiers.MSTest" Version="1.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
Expand Down
15 changes: 9 additions & 6 deletions Source/Tests/FunicularSwitch.Test/ImplicitCastStudy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FunicularSwitch.Test;

Expand All @@ -11,16 +10,20 @@ public class ImplicitCastStudy
public void ImplicitCastWithNullableStruct()
{
long? l = null;
Option<long> converted = l;
converted.Should().NotBeNull();
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
Option<long> converted = l;
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
converted.Should().NotBeNull();
}

[TestMethod]
public void ImplicitCastWithClass()
{
object? l = null;
Option<object> converted = l;
converted.Should().NotBeNull();
#pragma warning disable CS8604 // Possible null reference argument.
Option<object> converted = l;
#pragma warning restore CS8604 // Possible null reference argument.
converted.Should().NotBeNull();
}

[TestMethod]
Expand Down

0 comments on commit 9a38b38

Please sign in to comment.