From 72af2fd864a5b8de156c38a761d8aec9cacbf2b7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 29 Nov 2020 20:33:08 +0100 Subject: [PATCH] Fixed build error when no custom types are present --- .../IComputeShaderSourceAttributeGenerator.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs index c8abc15a..1ccd952e 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderSourceAttributeGenerator.cs @@ -62,12 +62,15 @@ namespace ComputeSharp.SourceGenerators // Helper that converts a sequence of strings into an array expression. // That is, this applies the following transformation: - // - { "S1", "S2" } => new[] { "S1", "S2" } - static ImplicitArrayCreationExpressionSyntax ImplicitArrayExpression(IEnumerable values) + // - { "S1", "S2" } => new string[] { "S1", "S2" } + static ArrayCreationExpressionSyntax ArrayExpression(IEnumerable values) { return - ImplicitArrayCreationExpression(InitializerExpression(SyntaxKind.ArrayInitializerExpression).AddExpressions( - values.Select(static value => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(value))).ToArray())); + ArrayCreationExpression( + ArrayType(PredefinedType(Token(SyntaxKind.StringKeyword))) + .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression())))) + .WithInitializer(InitializerExpression(SyntaxKind.ArrayInitializerExpression) + .AddExpressions(values.Select(static value => LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(value))).ToArray())); } // Create the compilation unit with the source attribute @@ -78,7 +81,7 @@ namespace ComputeSharp.SourceGenerators AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(structDeclarationSymbol.GetFullMetadataName()))), AttributeArgument(NestedPairsArrayExpression(GetProcessedMembers(structDeclarationSymbol, discoveredTypes).ToArray())), AttributeArgument(NestedPairsArrayExpression(GetProcessedMethods(structDeclaration, semanticModel, discoveredTypes).ToArray())), - AttributeArgument(ImplicitArrayExpression(GetProcessedTypes(discoveredTypes)))))) + AttributeArgument(ArrayExpression(GetProcessedTypes(discoveredTypes)))))) .WithOpenBracketToken(Token(TriviaList(Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))), SyntaxKind.OpenBracketToken, TriviaList())) .WithTarget(AttributeTargetSpecifier(Token(SyntaxKind.AssemblyKeyword)))) .NormalizeWhitespace()