Add a diagnostic for constructors with base constructors

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-02 23:25:23 +01:00
1 親 4ec30767ce
コミット 7e7b57cd67
6ファイル変更
+75

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

+1
ファイルの表示
@@ -79,3 +79,4 @@ CMPSD2D0069 | ComputeSharp.D2D1.Shaders | Warning | [Documentation](https://gith
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)
CMPSD2D0073 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -1080,4 +1080,20 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "A collection expression cannot be used in a pixel shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a constructor with a base constructor declaration.
/// <para>
/// Format: <c>"The constructor {0} has a base constructor declaration, which cannot be used in a D2D1 shader (only standalone constructors are allowed)"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidBaseConstructorDeclaration = new(
id: "CMPSD2D0073",
title: "Invalid base constructor declaration",
messageFormat: "The constructor {0} has a base constructor declaration, which cannot be used in a D2D1 shader (only standalone constructors are allowed)",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Only standalone constructors (with no base constructor declaration) can be used in a D2D1 shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
+8
ファイルの表示
@@ -662,6 +662,14 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
return updatedNode;
}
// Chaining constructors is not supported, so emit a diagnostic to inform the user.
// The rest of the code will work as usual, but the semantics of the other chained
// constructor being invoked is not preserved, so the resulting code is not the same.
if (constructorNode.Initializer is not null)
{
Diagnostics.Add(InvalidBaseConstructorDeclaration, node, constructor);
}
ShaderSourceRewriter shaderSourceRewriter = new(
SemanticModel,
DiscoveredTypes,
+1
ファイルの表示
@@ -66,3 +66,4 @@ CMPS0057 | ComputeSharp.Shaders | Warning | [Documentation](https://github.com/S
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)
CMPS0061 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+16
ファイルの表示
@@ -856,4 +856,20 @@ partial class DiagnosticDescriptors
isEnabledByDefault: true,
description: "A collection expression cannot be used in a compute shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for a constructor with a base constructor declaration.
/// <para>
/// Format: <c>"The constructor {0} has a base constructor declaration, which cannot be used in a shader (only standalone constructors are allowed)"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidBaseConstructorDeclaration = new(
id: "CMPS0061",
title: "Invalid base constructor declaration",
messageFormat: "The constructor {0} has a base constructor declaration, which cannot be used in a shader (only standalone constructors are allowed)",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "Only standalone constructors (with no base constructor declaration) can be used in a shader.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
+33
ファイルの表示
@@ -1419,6 +1419,39 @@ public class DiagnosticsTests
VerifyGeneratedDiagnostics<ComputeShaderDescriptorGenerator>(source, "CMPS0031", "CMPS0047", "CMPS0060");
}
[TestMethod]
public void InvalidBaseConstructorDeclaration()
{
const string source = """
using ComputeSharp;
public struct MyStruct
{
public MyStruct(int x)
{
}
public MyStruct(float x)
: this((int)x)
{
}
}
[GeneratedComputeShaderDescriptor]
public partial struct MyShader : IComputeShader
{
public ReadWriteBuffer<int> buffer;
public void Execute()
{
MyStruct value = new(3.14f);
}
}
""";
VerifyGeneratedDiagnostics<ComputeShaderDescriptorGenerator>(source, "CMPS0047", "CMPS0061");
}
/// <summary>
/// Verifies the output of a source generator.
/// </summary>