Skip to content

Commit 3ac1cc8

Browse files
authored
Merge pull request #44 from Cysharp/hadashiA/fix-net8
Fix compilation errors in .net8 with explicit static members
2 parents a40a091 + fa0c19d commit 3ac1cc8

File tree

11 files changed

+322
-98
lines changed

11 files changed

+322
-98
lines changed

sandbox/ConsoleApp/ConsoleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net7.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

sandbox/FileGenerate/FileGenerate.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55

66
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
77
<CompilerGeneratedFilesOutputPath>$(ProjectDir)..\Generated</CompilerGeneratedFilesOutputPath>

sandbox/FileGenerate/SimplePrimitive.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnitGenerator;
1+
using System;
2+
using UnitGenerator;
23

34
namespace FileGenerate
45
{
@@ -11,12 +12,16 @@ public readonly partial struct A
1112
public readonly partial struct B
1213
{
1314
}
14-
15+
1516
[UnitOf(typeof(int), UnitGenerateOptions.Comparable | UnitGenerateOptions.ArithmeticOperator | UnitGenerateOptions.ValueArithmeticOperator | UnitGenerateOptions.ParseMethod)]
1617
public readonly partial struct C
1718
{
1819
}
1920

21+
[UnitOf(typeof(Guid), UnitGenerateOptions.Comparable | UnitGenerateOptions.ParseMethod)]
22+
public readonly partial struct D
23+
{
24+
}
2025

2126
[UnitOf<int>]
2227
public readonly partial struct Aa

sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.A.g.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ readonly partial struct A
1818
#endif
1919
#if NET8_0_OR_GREATER
2020
, IEqualityOperators<A, A, bool>
21+
, IUtf8SpanFormattable
2122
#endif
2223
{
2324
readonly int value;
@@ -83,6 +84,11 @@ public override int GetHashCode()
8384
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
8485
((ISpanFormattable)value).TryFormat(destination, out charsWritten, format, provider);
8586
#endif
87+
#if NET8_0_OR_GREATER
88+
public bool TryFormat (Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
89+
((IUtf8SpanFormattable)value).TryFormat(utf8Destination, out bytesWritten, format, provider);
90+
#endif
91+
8692
// Default
8793

8894
private class ATypeConverter : System.ComponentModel.TypeConverter

sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.Aa.g.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ namespace FileGenerate
1212
[System.ComponentModel.TypeConverter(typeof(AaTypeConverter))]
1313
readonly partial struct Aa
1414
: IEquatable<Aa>
15-
#if NET7_0_OR_GREATER
16-
, IEqualityOperators<Aa, Aa, bool>
17-
#endif
1815
, IFormattable
16+
#if NET6_0_OR_GREATER
17+
, ISpanFormattable
18+
#endif
19+
#if NET8_0_OR_GREATER
20+
, IEqualityOperators<Aa, Aa, bool>
21+
, IUtf8SpanFormattable
22+
#endif
1923
{
2024
readonly int value;
2125

@@ -76,6 +80,15 @@ public override int GetHashCode()
7680

7781
public string ToString(string? format, IFormatProvider? formatProvider) => value.ToString(format, formatProvider);
7882

83+
#if NET6_0_OR_GREATER
84+
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
85+
((ISpanFormattable)value).TryFormat(destination, out charsWritten, format, provider);
86+
#endif
87+
#if NET8_0_OR_GREATER
88+
public bool TryFormat (Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
89+
((IUtf8SpanFormattable)value).TryFormat(utf8Destination, out bytesWritten, format, provider);
90+
#endif
91+
7992
// Default
8093

8194
private class AaTypeConverter : System.ComponentModel.TypeConverter

sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.Bb.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace FileGenerate
1212
[System.ComponentModel.TypeConverter(typeof(BbTypeConverter))]
1313
readonly partial struct Bb
1414
: IEquatable<Bb>
15-
#if NET7_0_OR_GREATER
15+
#if NET8_0_OR_GREATER
1616
, IEqualityOperators<Bb, Bb, bool>
17-
#endif
17+
#endif
1818
{
1919
readonly string value;
2020

sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.C.g.cs

Lines changed: 6 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ readonly partial struct C
1919
#endif
2020
#if NET7_0_OR_GREATER
2121
, IComparisonOperators<C, C, bool>
22-
, IParsable<C>
23-
, ISpanParsable<C>
2422
, IAdditionOperators<C, C, C>
2523
, ISubtractionOperators<C, C, C>
2624
, IMultiplyOperators<C, C, C>
@@ -32,7 +30,7 @@ readonly partial struct C
3230
#endif
3331
#if NET8_0_OR_GREATER
3432
, IEqualityOperators<C, C, bool>
35-
, IUtf8SpanParsable<C>
33+
, IUtf8SpanFormattable
3634
#endif
3735
{
3836
readonly int value;
@@ -98,6 +96,11 @@ public override int GetHashCode()
9896
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
9997
((ISpanFormattable)value).TryFormat(destination, out charsWritten, format, provider);
10098
#endif
99+
#if NET8_0_OR_GREATER
100+
public bool TryFormat (Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
101+
((IUtf8SpanFormattable)value).TryFormat(utf8Destination, out bytesWritten, format, provider);
102+
#endif
103+
101104
// UnitGenerateOptions.ParseMethod
102105

103106
public static C Parse(string s)
@@ -119,69 +122,6 @@ public static bool TryParse(string s, out C result)
119122
}
120123
}
121124

122-
#if NET7_0_OR_GREATER
123-
public static C Parse(string s, IFormatProvider? provider)
124-
{
125-
return new C(int.Parse(s, provider));
126-
}
127-
128-
public static bool TryParse(string s, IFormatProvider? provider, out C result)
129-
{
130-
if (int.TryParse(s, provider, out var r))
131-
{
132-
result = new C(r);
133-
return true;
134-
}
135-
else
136-
{
137-
result = default(C);
138-
return false;
139-
}
140-
}
141-
#endif
142-
143-
#if NET7_0_OR_GREATER
144-
public static C Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
145-
{
146-
return new C(int.Parse(s, provider));
147-
}
148-
149-
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out C result)
150-
{
151-
if (int.TryParse(s, provider, out var r))
152-
{
153-
result = new C(r);
154-
return true;
155-
}
156-
else
157-
{
158-
result = default(C);
159-
return false;
160-
}
161-
}
162-
#endif
163-
164-
#if NET8_0_OR_GREATER
165-
public static C Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
166-
{
167-
return new C(int.Parse(utf8Text, provider));
168-
}
169-
170-
public static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out C result)
171-
{
172-
if (int.TryParse(utf8Text, provider, out var r))
173-
{
174-
result = new C(r);
175-
return true;
176-
}
177-
else
178-
{
179-
result = default(C);
180-
return false;
181-
}
182-
}
183-
#endif
184-
185125
// UnitGenerateOptions.ArithmeticOperator
186126

187127
public static C operator +(C x, C y)

sandbox/Generated/UnitGenerator/UnitGenerator.SourceGenerator/FileGenerate.Cc.g.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ namespace FileGenerate
1212
[System.ComponentModel.TypeConverter(typeof(CcTypeConverter))]
1313
readonly partial struct Cc
1414
: IEquatable<Cc>
15-
#if NET7_0_OR_GREATER
16-
, IEqualityOperators<Cc, Cc, bool>
17-
#endif
1815
, IComparable<Cc>
19-
#if NET7_0_OR_GREATER
20-
, IComparisonOperators<Cc, Cc, bool>
21-
#endif
2216
, IFormattable
17+
#if NET6_0_OR_GREATER
18+
, ISpanFormattable
19+
#endif
2320
#if NET7_0_OR_GREATER
21+
, IComparisonOperators<Cc, Cc, bool>
2422
, IAdditionOperators<Cc, Cc, Cc>
2523
, ISubtractionOperators<Cc, Cc, Cc>
2624
, IMultiplyOperators<Cc, Cc, Cc>
@@ -29,6 +27,10 @@ readonly partial struct Cc
2927
, IUnaryNegationOperators<Cc, Cc>
3028
, IIncrementOperators<Cc>
3129
, IDecrementOperators<Cc>
30+
#endif
31+
#if NET8_0_OR_GREATER
32+
, IEqualityOperators<Cc, Cc, bool>
33+
, IUtf8SpanFormattable
3234
#endif
3335
{
3436
readonly int value;
@@ -90,6 +92,15 @@ public override int GetHashCode()
9092

9193
public string ToString(string? format, IFormatProvider? formatProvider) => value.ToString(format, formatProvider);
9294

95+
#if NET6_0_OR_GREATER
96+
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
97+
((ISpanFormattable)value).TryFormat(destination, out charsWritten, format, provider);
98+
#endif
99+
#if NET8_0_OR_GREATER
100+
public bool TryFormat (Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider) =>
101+
((IUtf8SpanFormattable)value).TryFormat(utf8Destination, out bytesWritten, format, provider);
102+
#endif
103+
93104
// UnitGenerateOptions.ArithmeticOperator
94105

95106
public static Cc operator +(Cc x, Cc y)

0 commit comments

Comments
 (0)