Added error for string literal expressions
このコミットが含まれているのは:
1 親
01623476ff
コミット
6653cba24f
4ファイル変更
+46
-1
検索条件に一致するファイルはありません
@@ -39,4 +39,5 @@ CMPS0031 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator,
|
||||
CMPS0032 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0033 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0034 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0035 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0035 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0036 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -494,5 +494,18 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
|
||||
isEnabledByDefault: true,
|
||||
description: "The unsafe modifier cannot be used in methods or functions used in a compute shader.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for a string literal.
|
||||
/// </summary>
|
||||
public static DiagnosticDescriptor StringLiteralExpression { get; } = new(
|
||||
id: "CMPS0036",
|
||||
title: "String literal expression",
|
||||
messageFormat: "String literal expressions cannot be used in a compute shader",
|
||||
category: typeof(IComputeShader).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "String literal expressions cannot be used in a compute shader.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
}
|
||||
@@ -316,6 +316,10 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
return updatedNode.WithToken(Literal(updatedNode.Token.ValueText + "L", 0d));
|
||||
}
|
||||
}
|
||||
else if (updatedNode.IsKind(SyntaxKind.StringLiteralExpression))
|
||||
{
|
||||
this.context.ReportDiagnostic(StringLiteralExpression, node);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
@@ -1070,6 +1070,33 @@ namespace ComputeSharp.Tests.Internals
|
||||
VerifyGeneratedDiagnostics<IComputeShaderSourceGenerator>(source, "CMPS0035");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StringLiteralExpression()
|
||||
{
|
||||
string source = @"
|
||||
using ComputeSharp;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
public class ReadWriteBuffer<T> { }
|
||||
}
|
||||
|
||||
namespace MyFancyApp.Sample
|
||||
{
|
||||
public struct MyShader : IComputeShader
|
||||
{
|
||||
public ReadWriteBuffer<float> buffer;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
_ = ""Hello world"";
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
VerifyGeneratedDiagnostics<IComputeShaderSourceGenerator>(source, "CMPS0036");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the output of a source generator.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする