Skip to content

Commit ddfc56b

Browse files
committed
🐛Record Result fix.
1 parent 33fcd94 commit ddfc56b

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

Tests/TedToolkit.Console/TestValidator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ public partial class DateTimeResult
1515
}
1616

1717
[GenerateValidResult<TestClass2>]
18-
public partial class TestClass2Result
18+
public partial class TestClass2Result;
19+
20+
21+
[GenerateValidResult<TestRecord>]
22+
public partial class TestRecordResult;
23+
24+
public record TestRecord
1925
{
26+
public int Value { get; init; } = 0;
2027
}
2128

2229
public struct TestStruct;

src/analyzers/TedToolkit.ValidResults.SourceGenerator/ValidResultsGenerator.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,11 @@ private static void GenerateItem(SourceProductionContext context, Dictionary<ISy
152152
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
153153
.WithAttributeLists([GeneratedCodeAttribute(typeof(ValidResultsGenerator))])
154154
.WithMembers([
155-
GenerateCreateTracker(IdentifierName(target.FullName).WithTypeParameterNames(parameterNames), true),
155+
GenerateCreateTracker(IdentifierName(target.FullName).WithTypeParameterNames(parameterNames),
156+
true),
156157
GenerateCreateTracker(IdentifierName(data.GetName().FullName), false),
157-
MethodDeclaration(IdentifierName(target.Name).WithTypeParameterNames(parameterNames), Identifier("ToValidResult"))
158+
MethodDeclaration(IdentifierName(target.Name).WithTypeParameterNames(parameterNames),
159+
Identifier("ToValidResult"))
158160
.WithTypeParameterNames(parameterNames)
159161
.WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)))
160162
.WithAttributeLists([
@@ -169,13 +171,15 @@ private static void GenerateItem(SourceProductionContext context, Dictionary<ISy
169171
]))
170172
.WithExpressionBody(ArrowExpressionClause(InvocationExpression(MemberAccessExpression(
171173
SyntaxKind.SimpleMemberAccessExpression,
172-
IdentifierName(target.Name).WithTypeParameterNames(parameterNames), IdentifierName("Ok")))
174+
IdentifierName(target.Name).WithTypeParameterNames(parameterNames),
175+
IdentifierName("Ok")))
173176
.WithArgumentList(ArgumentList(
174177
[
175178
Argument(IdentifierName("value"))
176179
]))))
177180
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken)),
178-
..GenerateStaticMembers(members, dictionary, trackerName, baseDataSymbol, extensionMethods, parameterNames)
181+
..GenerateStaticMembers(members, dictionary, trackerName, baseDataSymbol, extensionMethods,
182+
parameterNames)
179183
]),
180184
ClassDeclaration(trackerName)
181185
.WithTypeParameterNames(parameterNames)
@@ -282,6 +286,7 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateStaticMembers(IReadO
282286
.OfType<IMethodSymbol>()
283287
.Where(p => !p.ReturnType.IsRefLikeType)
284288
.Where(p => !p.IsStatic)
289+
.Where(p => p.Name is not "<Clone>$")
285290
.Where(p => !staticMethods.Contains(new MethodSignature(p))))
286291
if (method.MethodKind is MethodKind.Ordinary)
287292
yield return OrdinaryMethod(method, dictionary, trackerName, paramNames);
@@ -316,7 +321,8 @@ bool IsEffectivelyPublic(IMethodSymbol method)
316321
}
317322

318323
private static IEnumerable<MemberDeclarationSyntax> GenerateMembers(IReadOnlyCollection<ISymbol> members,
319-
Dictionary<ISymbol?, SimpleType> dictionary, string trackerName, ITypeSymbol? baseTypeSymbol, IReadOnlyCollection<ITypeParamName> paramNames)
324+
Dictionary<ISymbol?, SimpleType> dictionary, string trackerName, ITypeSymbol? baseTypeSymbol,
325+
IReadOnlyCollection<ITypeParamName> paramNames)
320326
{
321327
var propertyOrFieldNames = baseTypeSymbol?.GetMembers().OfType<IPropertySymbol>().Select(i => i.Name)
322328
.Concat(baseTypeSymbol.GetMembers().OfType<IFieldSymbol>().Select(i => i.Name)).ToArray() ?? [];
@@ -334,7 +340,8 @@ private static IEnumerable<MemberDeclarationSyntax> GenerateMembers(IReadOnlyCol
334340
.Where(p => !propertyOrFieldNames.Contains(p.Name))
335341
.Where(p => !p.Type.IsRefLikeType))
336342
yield return GenerateProperty(property.Type, property.Name, property.ContainingType,
337-
dictionary, property.GetMethod is not null, property.SetMethod is not null, property.Parameters);
343+
dictionary, property.GetMethod is not null, property.SetMethod is { IsInitOnly : false },
344+
property.Parameters);
338345

339346
foreach (var field in members
340347
.OfType<IFieldSymbol>()
@@ -365,7 +372,8 @@ private static MemberDeclarationSyntax OrdinaryMethod(IMethodSymbol method,
365372
}
366373

367374
private static MemberDeclarationSyntax StaticOrdinaryMethod(IMethodSymbol method,
368-
Dictionary<ISymbol?, SimpleType> dictionary, MethodParametersHelper.MethodType type, string trackerName, IReadOnlyCollection<ITypeParamName> paramNames)
375+
Dictionary<ISymbol?, SimpleType> dictionary, MethodParametersHelper.MethodType type, string trackerName,
376+
IReadOnlyCollection<ITypeParamName> paramNames)
369377
{
370378
return MethodParametersHelper.GenerateMethodByParameters(method,
371379
[..method.Parameters.Select(p => new ParameterRelay(p))],

0 commit comments

Comments
 (0)