diff --git a/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs b/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs index 86418169..3a29bc8d 100644 --- a/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs +++ b/src/ComputeSharp.SourceGenerators/Extensions/SyntaxNodeExtensions.cs @@ -58,6 +58,12 @@ namespace ComputeSharp.SourceGenerators.Extensions _ => semanticModel.GetTypeInfo(sourceType).Type! }; + // Do nothing if the type is just void + if (typeSymbol.SpecialType == SpecialType.System_Void) + { + return node; + } + string typeName = typeSymbol.ToDisplayString(ISymbolExtensions.FullyQualifiedWithoutGlobalFormat); discoveredTypes.Add((INamedTypeSymbol)typeSymbol); diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 38cf34f3..9c640fa4 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -153,7 +153,9 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters { this.currentMethod = node; - var updatedNode = (MethodDeclarationSyntax?)base.Visit(node); + var updatedNode = (MethodDeclarationSyntax?)base.Visit(node)!; + + updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, this.semanticModel, this.discoveredTypes); if (node!.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword))) { @@ -358,6 +360,8 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters .WithAttributeLists(List()) .WithIdentifier(Identifier($"__{this.currentMethod!.Identifier.Text}__{node.Identifier.Text}")); + updatedNode = updatedNode.ReplaceAndTrackType(updatedNode.ReturnType, node!.ReturnType, this.semanticModel, this.discoveredTypes); + if (node.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword))) { this.context.ReportDiagnostic(AsyncModifierOnMethodOrFunction, node); diff --git a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs index 3cf860e9..b490ce77 100644 --- a/tests/ComputeSharp.Tests/ShaderCompilerTests.cs +++ b/tests/ComputeSharp.Tests/ShaderCompilerTests.cs @@ -1,3 +1,4 @@ +using System.Threading; using ComputeSharp.Interop; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -27,5 +28,26 @@ namespace ComputeSharp.Tests row_major[ThreadIds.X] = log / dword; } } + + [TestMethod] + public void SpecialTypeAsReturnType() + { + ReflectionServices.GetShaderInfo(out _); + } + + [AutoConstructor] + public readonly partial struct FloatReturnType : IComputeShader + { + public readonly ReadWriteBuffer buffer; + + Float2 Foo(float x) => x; + + public void Execute() + { + static Float3 Bar(float x) => x; + + buffer[ThreadIds.X] = Foo(ThreadIds.X) + Bar(ThreadIds.X).XY; + } + } } }