Emit a diagnostic for collection expressions

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-29 00:23:37 +01:00
1 親 f934c04955
コミット b266308c8b
6ファイル変更
+60 -3

検索条件に一致するファイルはありません

+1
ファイルの表示
@@ -78,3 +78,4 @@ CMPSD2D0068 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0069 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0070 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0071 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0072 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+13
ファイルの表示
@@ -1067,4 +1067,17 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "An initializer expression cannot be used in a pixel shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a collection expression.
/// </summary>
public static readonly DiagnosticDescriptor CollectionExpression = new(
id: "CMPSD2D0072",
title: "Collection expression",
messageFormat: "A collection expression cannot be used in a pixel shader",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A collection expression cannot be used in a pixel shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
@@ -24,6 +24,14 @@ partial class HlslSourceRewriter
return base.VisitInitializerExpression(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitCollectionExpression(CollectionExpressionSyntax node)
{
Diagnostics.Add(CollectionExpression, node);
return base.VisitCollectionExpression(node);
}
/// <inheritdoc/>
public override SyntaxNode? VisitAwaitExpression(AwaitExpressionSyntax node)
{
+1
ファイルの表示
@@ -65,3 +65,4 @@ CMPS0056 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Ser
CMPS0057 | ComputeSharp.Shaders | Warning | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0058 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0059 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0060 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+13
ファイルの表示
@@ -843,4 +843,17 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "An initializer expression cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a collection expression.
/// </summary>
public static readonly DiagnosticDescriptor CollectionExpression = new(
id: "CMPS0060",
title: "Collection expression",
messageFormat: "A collection expression cannot be used in a compute shader",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A collection expression cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
+24 -3
ファイルの表示
@@ -1345,7 +1345,7 @@ public class DiagnosticsTests
}
[TestMethod]
public void InitializerExpression_ObjectCreation()
public void InvalidInitializerExpression_ObjectCreation()
{
const string source = """
using ComputeSharp;
@@ -1371,7 +1371,7 @@ public class DiagnosticsTests
}
[TestMethod]
public void InitializerExpression_ImplicitObjectCreation()
public void InvalidInitializerExpression_ImplicitObjectCreation()
{
const string source = """
using ComputeSharp;
@@ -1397,7 +1397,7 @@ public class DiagnosticsTests
}
[TestMethod]
public void InitializerExpression_CollectionInitializer()
public void InvalidInitializerExpression_CollectionInitializer()
{
const string source = """
using ComputeSharp;
@@ -1417,6 +1417,27 @@ public class DiagnosticsTests
VerifyGeneratedDiagnostics<ComputeShaderDescriptorGenerator>(source, "CMPS0031", "CMPS0047", "CMPS0059");
}
[TestMethod]
public void InvalidCollectionExpression()
{
const string source = """
using ComputeSharp;
[GeneratedComputeShaderDescriptor]
public partial struct MyShader : IComputeShader
{
public ReadWriteBuffer<int> buffer;
public void Execute()
{
int[] numbers = [1, 2, 3, 4];
}
}
""";
VerifyGeneratedDiagnostics<ComputeShaderDescriptorGenerator>(source, "CMPS0031", "CMPS0047", "CMPS0060");
}
/// <summary>
/// Verifies the output of a source generator.
/// </summary>