-
Notifications
You must be signed in to change notification settings - Fork 0
Remove UseProvidedBody string matching from DelegateBodySyntaxExtractor #96
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,9 +96,10 @@ private static string GenerateSourceForGroup( | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Generates source code from a fluent body pattern. First attempts to extract the delegate | ||
| /// body from a <c>UseProvidedBody</c> call in the syntax tree. If no such call is found, | ||
| /// falls back to executing the generator method and extracting the return value. | ||
| /// Generates source code from a fluent body pattern. Executes the generator method first | ||
| /// to obtain <see cref="FluentBodyResult"/>. If the result indicates a delegate body was | ||
| /// provided (via <see cref="FluentBodyResult.HasDelegateBody"/>), attempts to extract the | ||
| /// lambda body from the syntax tree. Otherwise, uses the runtime-evaluated return value. | ||
| /// </summary> | ||
| private static string GenerateFromFluentBodyPattern( | ||
| SourceProductionContext context, | ||
|
|
@@ -107,18 +108,6 @@ private static string GenerateFromFluentBodyPattern( | |
| INamedTypeSymbol containingType, | ||
| Compilation compilation) | ||
| { | ||
| string? delegateBody = DelegateBodySyntaxExtractor.TryExtractDelegateBody(methodInfo.Syntax); | ||
| if (delegateBody != null) | ||
| { | ||
| bool isVoidReturn = partialMethod.ReturnType.SpecialType == SpecialType.System_Void; | ||
| string bodyLines = FormatDelegateBodyForEmit(delegateBody, isVoidReturn); | ||
|
|
||
| return GeneratesMethodPatternSourceBuilder.GeneratePartialMethodWithBody( | ||
| containingType, | ||
| partialMethod, | ||
| bodyLines); | ||
| } | ||
|
|
||
| (FluentBodyResult? result, string? error) = GeneratesMethodExecutionRuntime.ExecuteFluentBodyGeneratorMethod( | ||
| methodInfo.Symbol, | ||
| partialMethod, | ||
|
|
@@ -134,10 +123,25 @@ private static string GenerateFromFluentBodyPattern( | |
| return string.Empty; | ||
| } | ||
|
|
||
| if (result!.HasDelegateBody) | ||
| { | ||
| string? delegateBody = DelegateBodySyntaxExtractor.TryExtractDelegateBody(methodInfo.Syntax); | ||
| if (delegateBody != null) | ||
| { | ||
|
Comment on lines
+126
to
+130
|
||
| bool isVoidReturn = partialMethod.ReturnType.SpecialType == SpecialType.System_Void; | ||
| string bodyLines = FormatDelegateBodyForEmit(delegateBody, isVoidReturn); | ||
|
|
||
| return GeneratesMethodPatternSourceBuilder.GeneratePartialMethodWithBody( | ||
| containingType, | ||
| partialMethod, | ||
| bodyLines); | ||
| } | ||
| } | ||
|
|
||
| return GeneratesMethodPatternSourceBuilder.GenerateSimplePartialMethod( | ||
| containingType, | ||
| partialMethod, | ||
| result!.ReturnValue); | ||
| result.ReturnValue); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetReturnExpression’s comment says the method “assumes … at most one return statement”, but the implementation uses FirstOrDefault(), which will silently pick the first return if there are multiple. Consider enforcing the assumption (e.g., SingleOrDefault + diagnostic) or updating the comment/logic so unexpected shapes don’t lead to extracting the wrong expression without any signal.