-
Notifications
You must be signed in to change notification settings - Fork 53
Fix source generator for void-returning activity functions #554
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
906d3ca
b8ef400
4dc963a
2ad2d80
844abb8
2fe8dd3
c94763f
b7a0de6
0e8964e
56b2951
c7dc22e
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 |
|---|---|---|
|
|
@@ -22,21 +22,24 @@ public class DurableFunction | |
| public DurableFunctionKind Kind { get; } | ||
| public TypedParameter Parameter { get; } | ||
| public string ReturnType { get; } | ||
| public bool ReturnsVoid { get; } | ||
|
|
||
| public DurableFunction( | ||
| string fullTypeName, | ||
| string name, | ||
| DurableFunctionKind kind, | ||
| TypedParameter parameter, | ||
| ITypeSymbol returnType, | ||
| ITypeSymbol? returnType, | ||
| bool returnsVoid, | ||
| HashSet<string> requiredNamespaces) | ||
| { | ||
| this.FullTypeName = fullTypeName; | ||
| this.RequiredNamespaces = requiredNamespaces; | ||
| this.Name = name; | ||
| this.Kind = kind; | ||
| this.Parameter = parameter; | ||
| this.ReturnType = SyntaxNodeUtility.GetRenderedTypeExpression(returnType, false); | ||
| this.ReturnType = returnType != null ? SyntaxNodeUtility.GetRenderedTypeExpression(returnType, false) : string.Empty; | ||
| this.ReturnsVoid = returnsVoid; | ||
| } | ||
|
|
||
| public static bool TryParse(SemanticModel model, MethodDeclarationSyntax method, out DurableFunction? function) | ||
|
|
@@ -59,12 +62,54 @@ public static bool TryParse(SemanticModel model, MethodDeclarationSyntax method, | |
| return false; | ||
| } | ||
|
|
||
| INamedTypeSymbol taskSymbol = model.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1")!; | ||
| INamedTypeSymbol returnSymbol = (INamedTypeSymbol)model.GetTypeInfo(returnType).Type!; | ||
| if (SymbolEqualityComparer.Default.Equals(returnSymbol.OriginalDefinition, taskSymbol)) | ||
| ITypeSymbol? returnTypeSymbol = model.GetTypeInfo(returnType).Type; | ||
| if (returnTypeSymbol == null || returnTypeSymbol.TypeKind == TypeKind.Error) | ||
| { | ||
| // this is a Task<T> return value, lets pull out the generic. | ||
| returnSymbol = (INamedTypeSymbol)returnSymbol.TypeArguments[0]; | ||
| function = null; | ||
| return false; | ||
| } | ||
|
|
||
| bool returnsVoid = false; | ||
| INamedTypeSymbol? returnSymbol = null; | ||
|
|
||
|
Comment on lines
+73
to
+74
|
||
| // Check if it's a void return type | ||
| if (returnTypeSymbol.SpecialType == SpecialType.System_Void) | ||
| { | ||
| returnsVoid = true; | ||
| // returnSymbol is left as null since void has no type to track | ||
| } | ||
| // Check if it's Task (non-generic) | ||
| else if (returnTypeSymbol is INamedTypeSymbol namedReturn) | ||
| { | ||
| INamedTypeSymbol? nonGenericTaskSymbol = model.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task"); | ||
|
Comment on lines
+83
to
+84
|
||
| if (nonGenericTaskSymbol != null && SymbolEqualityComparer.Default.Equals(namedReturn, nonGenericTaskSymbol)) | ||
| { | ||
| returnsVoid = true; | ||
| // returnSymbol is left as null since Task (non-generic) has no return type to track | ||
| } | ||
| // Check if it's Task<T> | ||
| else | ||
| { | ||
| INamedTypeSymbol? taskSymbol = model.Compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1"); | ||
| returnSymbol = namedReturn; | ||
| if (taskSymbol != null && SymbolEqualityComparer.Default.Equals(returnSymbol.OriginalDefinition, taskSymbol)) | ||
| { | ||
| // this is a Task<T> return value, lets pull out the generic. | ||
| ITypeSymbol typeArg = returnSymbol.TypeArguments[0]; | ||
| if (typeArg is not INamedTypeSymbol namedTypeArg) | ||
| { | ||
| function = null; | ||
| return false; | ||
| } | ||
| returnSymbol = namedTypeArg; | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // returnTypeSymbol is not INamedTypeSymbol, which is unexpected | ||
| function = null; | ||
| return false; | ||
| } | ||
|
|
||
| if (!SyntaxNodeUtility.TryGetParameter(model, method, kind, out TypedParameter? parameter) || parameter == null) | ||
|
|
@@ -79,12 +124,18 @@ public static bool TryParse(SemanticModel model, MethodDeclarationSyntax method, | |
| return false; | ||
| } | ||
|
|
||
| // Build list of types used for namespace resolution | ||
| List<INamedTypeSymbol> usedTypes = new() | ||
| { | ||
| returnSymbol, | ||
| parameter.Type | ||
| }; | ||
|
|
||
| // Only include return type if it's not void | ||
| if (returnSymbol != null) | ||
| { | ||
| usedTypes.Add(returnSymbol); | ||
| } | ||
|
|
||
| if (!SyntaxNodeUtility.TryGetRequiredNamespaces(usedTypes, out HashSet<string>? requiredNamespaces)) | ||
| { | ||
| function = null; | ||
|
|
@@ -93,7 +144,7 @@ public static bool TryParse(SemanticModel model, MethodDeclarationSyntax method, | |
|
|
||
| requiredNamespaces!.UnionWith(GetRequiredGlobalNamespaces()); | ||
|
|
||
| function = new DurableFunction(fullTypeName!, name, kind, parameter, returnSymbol, requiredNamespaces); | ||
| function = new DurableFunction(fullTypeName!, name, kind, parameter, returnSymbol, returnsVoid, requiredNamespaces); | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.